实现将十进制数转二进制数
1 #include<stdio.h>
2 int main()
3 {
4 int num = 10; //随便定义的十进制数
5 int binary = 0;
6 int i = 1;
7 while(num>0)
8 {
9 binary += (num%2)*i;
10 num/=2;
11 i *= 10;
12 }
13 printf("binary = %d\n",binary);
14 return 0;
15 }