C语言 逆序数
#include<stdio.h>
int main(){
int Reverse(int x);
int x;
printf("请输入一个整数:");
scanf("%d",&x);
printf("逆序数为:%d",Reverse(x));
return 0;
}
int Reverse(int x){
int rev=0;
while(x!=0) { //以x=123为例 ,纵向读
rev*=10; //rev=0 * rev=30 * rev=320 *
rev+=x%10; //rev=0+3=3 * rev=30+2=32 * rev=320+1=321 *
x/=10; //x=12 * x=1 * x=0 *
}
return rev;
}