用c语言编程计算1-20 的 30位二进制和十进制,并且一行一行的输出
时间: 2023-04-04 13:01:22 浏览: 72
二进制:
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 20; i++) {
int num = i;
int binary[30] = {};
for (j = ; num > ; j++) {
binary[j] = num % 2;
num /= 2;
}
printf("%2d: ", i);
for (j = 29; j >= ; j--) {
printf("%d", binary[j]);
}
printf("\n");
}
return ;
}
```
十进制:
```c
#include <stdio.h>
int main() {
int i, j;
for (i = 1; i <= 20; i++) {
int num = i;
int decimal[30] = {};
for (j = ; num > ; j++) {
decimal[j] = num % 10;
num /= 10;
}
printf("%2d: ", i);
for (j = 29; j >= ; j--) {
printf("%d", decimal[j]);
}
printf("\n");
}
return ;
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)