输入一个整数,将它逆序输出。要求定义并调用函数reverse(number),它的功能是返回number的逆序数。
1个回答
2013-05-14
展开全部
#include <stdio.h>
int reverse_num(int n)
{
int m = n%10;
int i = n/10;
while (i > 0)
{
int a = i%10;
m *= 10;
m += a;
i /= 10;
}
return m;
}
int main()
{
int n = 0;
int m = 0;
printf("Please input a number:\n");
scanf("%d", &n);
printf("The reverse number is : %d\n",reverse_num(n));
return 0;
}
int reverse_num(int n)
{
int m = n%10;
int i = n/10;
while (i > 0)
{
int a = i%10;
m *= 10;
m += a;
i /= 10;
}
return m;
}
int main()
{
int n = 0;
int m = 0;
printf("Please input a number:\n");
scanf("%d", &n);
printf("The reverse number is : %d\n",reverse_num(n));
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询