/*
题目很简单,完成函数reverse,要求实现把给定的一个整数取其相反数的功能,举两个例子如下:x = 123, return 321 x = -123, return -321
挑战规则:
1.完成功能函数即可,main函数只是方便你自行测试。
*/
#include <stdio.h>
int Reserved( const int num )
{
int result = 0;
int zeronine,temp;
int large = 1;
temp = num;
do {
result *= large;
zeronine = temp % 10;
temp = temp / 10;
result += zeronine;
large = 10;
printf("temp: %d, zeronine = %d , result = %d\n",temp,zeronine,result);
}while (temp);
return -result;
}
int main()
{
printf("%d\n",Reserved(12));
printf("%d\n",Reserved(123));
printf("%d\n",Reserved(-321));
return 0;
}
挑战失败,难道这么写有问题吗?