用c语言将123倒序输出
时间: 2023-05-13 14:04:25 浏览: 71
可以使用以下代码实现:
#include <stdio.h>
int main() {
int num = 123;
while (num > 0) {
int digit = num % 10;
printf("%d", digit);
num /= 10;
}
return 0;
}
相关问题
c语言用数组倒序输出一组数
以下是C语言用数组倒序输出一组数的例子:
```c
#include <stdio.h>
#define N 10
int main() {
int a[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int i, t;
printf("原始数组是:\n");
for (i = 0; i < N; i++) {
printf("%d ", a[i]);
}
printf("\n倒序输出数组:\n");
for (i = N - 1; i >= 0; i--) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
```
c语言递归函数倒序输出
下面是一个C语言递归函数倒序输出的例子:
```c
#include <stdio.h>
void reverse_print(int num) {
if (num == 0) { // 递归结束条件
return;
}
printf("%d", num % 10); // 输出最后一位数字
reverse_print(num / 10); // 递归调用,去掉最后一位数字
}
int main() {
int num = 12345;
reverse_print(num); // 输出:54321
return 0;
}
```
相关推荐
![](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)