c语言中从标准输入上读入整数正整数n,使用递归函数逆序输出n的各位数字。例如123输出321,1
#include <stdio.h>
int main()
{
int a, t;
scanf ("%d", &a);
t = 0;
while (a){
t= t*10+a%10;
a/=10;
}
printf("%d\n", t);
return 0;
}
追问可以用正规一点的格式吗?这样有点乱
追答#include <stdio.h>
int main()
{
int a, t = 0, g;
scanf ("%d", &a);
while (a!=0)
{
g = a%10;
t= t*10+g;
a/=10;
}
printf("%d\n", t);
return 0;
}
这也乱,我也是醉了
追问谢了
温馨提示:答案为网友推荐,仅供参考
相似回答
...将输入的一个正整数以相反的顺序输出。例如输入1234,输出4321_百度...答:include<stdio.h> void main(){ int a,b,c,d,e,f,g,h,sum;scanf("%d",&a);if(a>=1000&&a<=9999){ b=a/1000;c=a%10;d=a/1000;e=a/100;f=e%10;g=a/10;h=g%10;sum=c*1000+f*10+h*100+d;printf("转换后:%d",sum);} else printf("此数不为4位数");} ...