整数反序输出,输入123,输出3210
#include <stdio.h>
int main()
{
int m,sum=0,t;
scanf("%d",&m);
while(t!=0)
{
t=m%10;
m=m/10;
sum=sum*10+t;
}
printf("%d",sum);
return 0;
}
整数反序输出,输入123,输出3210
#include <stdio.h>
int main()
{
int m,sum=0,t;
scanf("%d",&m);
while(t!=0)
{
t=m%10;
m=m/10;
sum=sum*10+t;
}
printf("%d",sum);
return 0;
}
问题已解决,改变循环条件t!=0改为m>0
#include <stdio.h>
int main()
{
int m,sum=0,t;
scanf("%d",&m);
while(m>0)
{
t=m%10;
m=m/10;
sum=sum*10+t;
}
printf("%d",sum);
return 0;
}