题解 | #数字颠倒#
数字颠倒
http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
//取整数的每一位可用%
#include <stdio.h>
int main()
{
int num = 0;
char str[32] = {0};
int i = 0;
if(scanf("%d", &num))
{
if(num > 0)
{
while(num)
{
//取num的每一位
str[i] = (num % 10) + '0'; //+'0'是为了把数字转换为字符
i++;
num /= 10;
}
}
else
{
str[i] = num + '0';
}
printf("%s\n", str);
}
return 0;
}