Created
January 16, 2015 18:06
-
-
Save ahmedeshaan/f075873d760d501015b4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Question: Take an integer(DECIMAL) input and convert it to Binary number | |
int main() | |
{ | |
int binary_output[10]; | |
int i=1,j,n=-52; | |
// To avoid Negative Input | |
if(n<0) { | |
n = n +(-n*2); | |
} | |
while(n) { | |
// Put Moulous input in an array | |
binary_output[i] = n % 2; | |
// Devided nth number by 2 in round | |
n /= 2; | |
i++; | |
} | |
for(j=i-1; j>=1;j--) { | |
// Print the stored array input | |
printf("%d",binary_output[j]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok.