Skip to content

Instantly share code, notes, and snippets.

@ahmedeshaan
Created January 16, 2015 18:06
Show Gist options
  • Save ahmedeshaan/f075873d760d501015b4 to your computer and use it in GitHub Desktop.
Save ahmedeshaan/f075873d760d501015b4 to your computer and use it in GitHub Desktop.
// 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;
}
@amitMist
Copy link

ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment