问题如下:
从键盘上读取一个整数
将其转换为二进制等价物并在屏幕上打印转换后的数值
将其转换为十六进制等价物,并将转换后的数值打印在屏幕上
我的代码如下
#include
int main()
{
int num
int a0,a1,a2,a3,a4,a5,a6,a7;
int b1,b2,b3,b4,b5,b6,b7;
int c0,c1,c2,c3,c4,c5,c6,c7;
int d1,d2,d3,d4,d5,d6,d7;
scanf("%d",&num)
a0 = num%2;
b1 = num /2;
a1 = b1 %2;
b2 = b1 /2;
a2 = b2 %2;
b3 = b2 /2;
a3 = b3 %2;
b4 = b3 /2;
a4 = b3 %2;
b5 = b4 /2;
a5 = b5 %2;
b6 = b5 /2;
a6 = b6 %2;
b7 = b6 /2;
a7 = b7 %2;
c0 = num%16;
c1 = num /16;
d1 = c1 %16;
c2 = c1 /16;
d2 = c2 %16;
c3 = c2 /16;
d3 = c3 %16;
c4 = c3 /16;
d4 = c4 %16;
c5 = c4 /16;
d5 = c5 %16;
c6 = c5 /16;
d6 = c6 %16;
c7 = c6 /16;
d7 = c7 %16;
printf("num=%d binary numbers are:%d%d%d%d%d%d%d%d",num,a7,a6,a5,a4,a3,a2,a1,a0);
printf("num=%d Hexadecimal numbers are:%d%d%d%d%d%d%d%d",num,c7,c6,c5,c4,c3,c2,c1,c0);
return 0;
}
但是代码无法运行
可以帮我检查一下我的代码的错误在哪里
int num;