高手,请教一个问题!!!

doublesong 2004-09-11 03:53:47
...
int x;
scanf("%d",&x);
...

请问如何把x的数值反向输出.
如:
input:123 output:321

thanks.
...全文
63 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
o1n 2004-09-11
  • 打赏
  • 举报
回复
楼上方法比我自己做的好。
我把楼上的方法复制了一下。
#include <stdio.h>
#include <string.h>
#include <iostream.h>
void main()
{
int x;
scanf("%d",&x);

for ( ; x ; x /= 10)
printf("%d",x % 10);



}
Squall1009 2004-09-11
  • 打赏
  • 举报
回复
基本符合要求
#include<stdio.h>
void main()
{
int x,y;
printf("请输入数字: ");
scanf("%d",&x);
y=0;
do{
y=y*10+x%10;
x=x/10;
}while(x);
printf("%d\n",y);
}
timgreen 2004-09-11
  • 打赏
  • 举报
回复
打错了是printf
timgreen 2004-09-11
  • 打赏
  • 举报
回复
for ( ; x ; x /= 10) fprint("%i",x % 10);

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧