算法收录
/*将一个输入的整数反序打印出来。
例如:输入1234
输出 4321
输入-4321
输出-1234
*/
#include <stdio.h>
/*将一个输入的整数反序打印出来。
例如:输入1234
输出 4321
输入-4321
输出-1234
*/
void printopp(long int n);
int main (int argc, char* argv[])
{
long int n;
scanf("%ld",&n);
printopp(n);
printf("\n");
return 0;
}
void printopp(long int n)
{
int i = 0;
if(n == 0)
{
return ;
}
else
while(n)
{
/* 下面的这个if很nice,解决了负数的问题*/
if (i == 0 || n > 0)
{
printf("%ld", n % 10);
}
else
printf("%ld", -n % 10);
i++;
n /= 10;
}
}