| Current Path : /var/www/html/bibhas.ghoshal/ITP_2019/lab/ |
| Current File : /var/www/html/bibhas.ghoshal/ITP_2019/lab/decimal2bin.c |
#include <stdio.h>
#include <math.h>
int main()
{
int n;
long long binaryNumber = 0;
int remainder, i = 1, step = 1;
printf("Enter a decimal number: ");
scanf("%d", &n);
while (n!=0)
{
remainder = n%2;
printf("Step %d: %d/2, Remainder = %d, Quotient = %d\n", step++, n, remainder, n/2);
n /= 2;
binaryNumber += remainder*i;
i *= 10;
}
printf("%d in decimal = %lld in binary",binaryNumber);
return 0;
}