每日一题
输入一个数字,使它逆序输出。例如输入12345输出54321
||||首先声明所有代码都是经过我测试可以直接使用。|||
**本题思路:**首先获取它的个位数字,十位数字,百位数字,用获取的数字分别乘以10的n次方,并每次相加。
其中pow(x,y);表示x的y次方,它需要头文件#include<math.h>
#include<stdio.h>
#include<math.h>
int hanshu(int num) {
int count=0;//count计数器用来计算它是几位数
int num1=num;
while(num1!=0){
num1=num1/10;
count=count+1;
}
int x=0,y=0;
while( num>0) {
x=num%10;//x为它的个位数,十位数,百位数的数字
num=num/10;
y=y+pow(10,count-1)*x;
count--;
}
return y;
}
int main() {
int n;
scanf("%d", &n);
int sn = hanshu(n);
printf("所求的数为%d", sn);
}
输入:153
输出: