#include<stdio.h>
#include<stdlib.h>
void numReverse(int num);
void numReverseWithoutArr(int num);
void main(){
numReverse(123459);
getchar();
}
void shuiXian(){
//求水仙花数(一个三位数,其各位数字的立方和等于该数本身)
int num, f, s, t;
for (num = 100; num <= 999; num++){
f = num % 10;
s = num % 10 / 10;
t = s / 100;
if (num == f*f*f + s*s*s + t*t*t){
printf("%d,%d,%d,%d\n", num, f, s, t);
}
}
}
int get10(int n ){ //获取n*10的数
int res = 1;
for (int i = 0; i < n; i++){
res *= 10;
}
return res;
}
void numReverse(int num){ //整数倒置, 用str数组暂存数据
int str[10];
int i = 0;
int length; //变化后的数组长度
int res = 0;
int j = 0;
for (;num;i++){
str[i] = num % 10;
num /= 10;
}
length = i;
while (j < length){
res += str[j] *get10(length-j-1);
j++;
}
printf("%d", res);
}
void numReverseWithoutArr(int num){ //整数倒置, 不用str数组暂存数据
//123
int res = 0;
for (int i = 0;num; i++){
res = num % 10 *get10(i-1);
num /= 10;
}
printf("%d", res);
}