标签:
问题:
输入一个正整数(<10000),输出颠倒后的整数。
【样例输入】1234
【样例输出】4321
回答:
#include <stdio.h>
int main()
{
int num ;
scanf("%d",&num);
int x,y,z,n,result;
if(num > 999)
{
x = num / 1000;
y = num % 1000 / 100;
z = num % 1000 % 100 / 10;
n = num % 1000 % 100 % 10;
result = n * 1000 + z * 100 + y * 10 + x;
}
else if(num > 99 )
{
x = num / 100;
y = num % 100 / 10;
z = num % 100 % 10;
result = z * 100 + y * 10 + x;
}else if(num > 9)
{
x = num / 10;
y = num % 10 ;
result = y * 10 + x;
}else
{
result = num;
}
printf("%d\n",result);
return 0;
}
标签:
原文地址:http://www.cnblogs.com/benchao/p/4523799.html