C语言中怎么把一个任意的数倒序输出.?知道的请告诉一下,谢谢.

是这样的,想请问下,C语言中怎么把一个任意的数倒序输出.?知道的请告诉一下,谢谢.
最新回答
琳开韵味沟

2024-10-14 08:27:50

需要准备的材料分别有:电脑、C语言

编译器

1、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp。

2、在test.cpp文件中,输入C语言代码:。

int a = 100;

while(a != 0) {

int b = a % 10;

if (b > 0)

printf("%d", b);

a /= 10;

}

3、编译器运行test.cpp文件,此时成功将数进行了逆序输出,例如100输出了1。

我恋↘爱乐

2024-10-14 09:47:43

参考下面代码,r就是结果

int n,i,r;
r = 0;
scanf("%d", &n);
while (n !=0)
{
i = n %10;
r = r * 10 + i;
n = n /10;
}
printf("%d", r);
蝶舞╰︶櫻婲落ペ

2024-10-14 08:18:35

#include<stdio.h>
main()
{
int x;
scanf("%d",&x);
while(x%10==0)x/=10; //跳过末尾的0
while(x>0){printf("%d",x%10); x/=10;} //其余数字倒序输出
printf("\n");
}
追问
若是101呢?
追答
101倒过来还是101啊。
三生路

2024-10-14 09:03:43

#include <stdio.h>
int main()
{
int x,b;

int y=0;

scanf("%d",&x);

while(x!=0){

b=x%10;

x=x/10;

y=y*10+b;

} printf("%d\n",y);

}
稳成老狗,谢谢
一身懵逼正气

2024-10-14 08:34:59

用字符数组储存没一位数字