1、本题要求实现一个求整数的逆序数的简单函数。
函数接口定义:int reverse( int number );
其中函数reverse须返回用户传入的整型number的逆序数。
裁判测试程序样例:
#include <stdio.h>
int reverse( int number );
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", reverse(n));
return 0;
}
#include<stdio.h>
#include<windows.h>
#pragma warning(disable:4996)
int reverse(int number)
{
int sum = 0;
int result = 0;
if (number < 0)//number为负数时只需当成正数一样看待
{
printf("-");
number = number*(-1);
}
while (number)
{
result = number % 10;
sum = sum * 10 + result;
number = number / 10;
}
return sum;
}
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", reverse(n));
system("pause");
return 0;
}
来源:CSDN
作者:钢钢钢不爽
链接:https://blog.csdn.net/weixin_45672178/article/details/104358512