已知a为3位整数,用c++编写程序,求其反序数并存入变量b后输出。
时间: 2023-04-10 15:01:15 浏览: 74
我可以回答这个问题。以下是用C语言编写的程序:
#include <stdio.h>
int main() {
int a, b = 0;
printf("请输入一个3位整数:");
scanf("%d", &a);
while (a > 0) {
b = b * 10 + a % 10;
a /= 10;
}
printf("反序数为:%d\n", b);
return 0;
}
相关问题
运用c语言编写程序,求其反序数并存入变量b后输出
可以使用以下代码实现:
```c
#include <stdio.h>
int main() {
int a = 12345;
int b = ;
while (a > ) {
b = b * 10 + a % 10;
a /= 10;
}
printf("反序数为:%d\n", b);
return ;
}
```
输出结果为:
```
反序数为:54321
```
用c语言制作输入一个4位整数放入变量a中,编写程序,求其反序数存入变量b后输出。
以下是用C语言编写的程序,可以实现输入一个4位整数,求其反序数并输出:
```
#include <stdio.h>
int main() {
int a, b;
printf("请输入一个4位整数:");
scanf("%d", &a);
b = (a % 10) * 1000 + (a / 10 % 10) * 100 + (a / 100 % 10) * 10 + (a / 1000);
printf("反序数为:%d\n", b);
return 0;
}
```
这个程序首先通过 `scanf` 函数获取用户输入的一个4位整数,并将其存储在变量 `a` 中。然后,通过一些简单的数学运算,计算出该整数的反序数,并将其存储在变量 `b` 中。最后,使用 `printf` 函数将反序数输出到屏幕上。
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)