#include <stdio.h>
#include <math.h>
//两种逆序方式
int main(){
int x;
int y=0;
//100逆序为1
scanf("%d",&x);
while(x==0){
y=x;
break;
}
while(x>0){
y=y*10+(x%10);
x=x/10;
}
while(x<0){
y=y*10+(x%10);
x=x/10;
}
printf("%d\n",y);
//100逆序为001
scanf("%d",&x);
while(x==0){
y=x;
printf("%d",y);
break;
}
while(x>0){
y=x%10;
printf("%d",y);
x=x/10;
}
int count=1; //count用来计数,当x<0时先输出“-”再逆序
while(x<0){
if(count==1){
printf("-");
count++;
}
y=-x%10;
printf("%d",y);
x=x/10;
}
return 0;
}
整数逆序
最新推荐文章于 2022-08-17 18:18:21 发布