How to Convert Decimal Number into Binary in C Programming

by Dinesh 2013-12-24 19:43:58

How to Convert Decimal Number into Binary in C Programming


#include
int main(){
long int decimalNumber,remainder,quotient;
int binaryNumber[100],i=1,j;
printf("Enter any decimal number: ");
scanf("%ld",&decimalNumber);
quotient = decimalNumber;
while(quotient!=0){
binaryNumber[i++]= quotient % 2;
quotient = quotient / 2;
}
printf("Binary value of decimal number %d: ",decimalNumber);
for(j = i -1 ;j> 0;j--)
printf("%d",binaryNumber[j]);
return 0;
}


Sample output:
Enter any decimal number: 50
Binary value of decimal number 50: 110010
1040
like
0
dislike
0
mail
flag

You must LOGIN to add comments