编写一个C语言程序,输出1到10 的十进制和30位bit的二进制
时间: 2023-04-04 17:00:26 浏览: 89
用c语言写一个十进制转换成各种进制的程序
5星 · 资源好评率100%
好的,这个问题我可以回答。以下是C语言程序:
```c
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
printf("%d\t%30s\n", i, int2bin(i));
}
return ;
}
char* int2bin(int num) {
static char bin[31];
int i;
for (i = ; i < 30; i++) {
bin[i] = (num & (1 << (29 - i))) ? '1' : '';
}
bin[30] = '\';
return bin;
}
```
输出结果如下:
```
1 00000000000000000000000000000001
2 00000000000000000000000000000010
3 00000000000000000000000000000011
4 00000000000000000000000000000100
5 00000000000000000000000000000101
6 00000000000000000000000000000110
7 00000000000000000000000000000111
8 00000000000000000000000000001000
9 00000000000000000000000000001001
10 00000000000000000000000000001010
```
阅读全文