用交换语句输入一三位正整数 逆序输出
时间: 2023-07-18 10:32:44 浏览: 93
好的,以下是C语言代码实现:
```c
#include <stdio.h>
int main() {
int num;
printf("请输入一个三位正整数:");
scanf("%d", &num);
int a = num / 100;
int b = num / 10 % 10;
int c = num % 10;
int temp;
temp = a;
a = c;
c = temp;
printf("%d\n", 100 * a + 10 * b + c);
return 0;
}
```
这里使用了整型变量来存储输入的数字,并通过除法和取模运算获取每一位数字,然后通过交换变量的值来实现逆序输出。
相关问题
用C语言输入一三位正整数 逆序输出
好的,以下是C语言代码实现:
```c
#include <stdio.h>
#include <string.h>
int main() {
char num[4];
printf("请输入一个三位正整数:");
scanf("%s", num);
int len = strlen(num);
for (int i = len - 1; i >= 0; i--) {
printf("%c", num[i]);
}
printf("\n");
return 0;
}
```
这里使用了字符数组来存储输入的数字,并使用`strlen`函数获取数字的长度,然后倒序遍历输出每一位数字。
用c语言编写,从键盘输入一个三位正整数,逆序输出
好的,这是一个很基础的 C 语言编程问题。下面是代码实现:
```c
#include <stdio.h>
int main() {
int num, reverse_num = 0;
printf("请输入一个三位正整数:");
scanf("%d", &num);
while (num != 0) {
reverse_num = reverse_num * 10 + num % 10;
num /= 10;
}
printf("逆序输出:%d\n", reverse_num);
return 0;
}
```
这段代码首先从键盘输入一个三位正整数,然后通过循环逆序输出它。在循环中,每次将 reverse_num 的值乘以 10 并加上 num 的个位数,然后将 num 除以 10 向下取整。最后输出逆序后的数字即可。
希望能够帮助到你!
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)