The original question is as follows :
7-3 逆序的三位数 (10point(s))
程序每次读入一个正3位数,然后输出按位逆序的数字。注意:当输入的数字含有结尾的0时,输出不应带有前导的0。比如输入700,输出应该是7。
输入格式:
每个测试是一个3位的正整数。
输出格式:
输出按位逆序的数。
输入样例:
123
输出样例:
321
***Note the title of conditions, with particular attention to data - such as 700 and 710.
code show as below:
// date:2020/3/4
// author:xiezhg5
#include <stdio.h>
int main(void)
{
int n,i,j,k;
scanf("%d",&n);
i=(int)(n/100); //百位数字
j=(int)(n-100*i)/10; //十位数字
k=(int)(n-100*i-10*j); //个位数字
//判断形如700这样的数据
if(k==0&&j==0)
printf("%d\n",i);
//判断形如710这样的数据
else if(k==0&&j!=0)
printf("%d%d\n",j,i);
//逆序输出
else
printf("%d%d%d\n",k,j,i);
return 0;
}