用C语言编程输出从1到10的十进制和30位bit二进制
时间: 2023-04-04 20:00:22 浏览: 108
1. 用C语言编程输出从1到10的十进制和30位bit二进制。
十进制输出:
```c
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
printf("%d ", i);
}
return ;
}
```
二进制输出:
```c
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
int num = i;
int binary[30] = {};
int index = ;
while (num > ) {
binary[index++] = num % 2;
num /= 2;
}
for (int j = 29; j >= ; j--) {
printf("%d", binary[j]);
}
printf(" ");
}
return ;
}
```
输出结果为:
```
1 2 3 4 5 6 7 8 9 10
000000000000000000000000000001
000000000000000000000000000010
000000000000000000000000000011
000000000000000000000000000100
000000000000000000000000000101
000000000000000000000000000110
000000000000000000000000000111
000000000000000000000000001000
000000000000000000000000001001
000000000000000000000000001010
```
阅读全文