#include <stdio.h>
int main()
{
int decimal,temp,binary=0;
int rem,place = 1;
printf("Enter any decimal number: ");
scanf("%d",&decimal);
temp = decimal; ///saving the value to another variable
while(temp > 0)
{
rem = temp % 2;
binary = (rem * place) + binary; /// convert to binary
temp /= 2;
place *= 10;
}
printf("
Binary number = %d
", binary);
return 0;
}
Output
Enter any decimal number:10
Enter any decimal number:1010
Add your comment