//十进制数转换为二进制数
include <stdio.h>
long long convertDemicalToBinary(int n);
int main()
{
int n;
printf("输入一个十进制数:");
scanf("%d", &n);
printf("十进制数%d转换为二进制数%lld.\n", n, convertDemicalToBinary(n));
return 0;
}
long long convertDemicalToBinary(int n)
{
long long binary = 0;
int r, i = 1, step = 1;
while (n != 0)
{
r = n % 2;
printf("Step %d:%d/2,余数是:%d,商是:%d\n", step++, n, r, n / 2);
n = n / 2;
binary = binary + i * r;
i = i * 10;
}
return (binary);
}