7-3 逆序的三位数(10分)
程序每次读入一个正3位数,然后输出按位逆序的数字。注意:当输入的数字含有结尾的0时,输出不应带有前导的0。比如输入700,输出应该是7。
输入格式:
每个测试是一个3位的正整数。
输出格式:
输出按位逆序的数。
输入样例:
123
输出样例:
321
题解:
#include <stdio.h>
#include <math.h>
int main()
{
int num = 0;
scanf("%d", &num);
int cnt = 0; // 计算位数
int t = num;
while(t)
{
cnt++;
t /= 10;
}
int r = 0;
while(num)
{
r += (num % 10) * pow(10, cnt - 1);
cnt--;
num /= 10;
}
printf("%d\n", r);
return 0;
}