forked from keshavsingh4522/hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request keshavsingh4522#684 from AniketNayek3101/master
Decimal to Binary Converter
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include<stdio.h> | ||
#include<math.h> | ||
int change(int n); | ||
int main() | ||
{ | ||
int n; | ||
printf("Enter a number in decimal : "); | ||
scanf("%d",&n); | ||
int m = change(n); | ||
printf ("The number %d in binary is %d",n,m); | ||
} | ||
int change(int n) | ||
{ | ||
int dec=0,i=1,rem; | ||
while(n!=0) | ||
{ | ||
rem = n % 2; | ||
n /= 2; | ||
dec += rem * i; | ||
i *= 10; | ||
} | ||
return dec; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters