题目输入一个整数,将其倒序输出
要求 1 假设最低为位0,则将其与最近的非零位调换,然后倒序输出
例如 (1700800 --> 8000071)
2 需要保留之前的符号,例如(-123 —> -321)
3 12345 ----> 54321
#include<stdio.h>
#include<string.h>
int main()
{
while (1) {
int num, temp;
int m_flag = 0;
int result = 0;
int i = 0;
int count = 0;
scanf("%d",&num);
while (num) {
temp = num % 10;
while ((temp == 0) && (m_flag == 0)) {
count++;
num = num / 10;
temp = num % 10;
}
for (i = 0; i < count; i++) {
temp *= 10;
}
count = 0;
m_flag++;
result = temp + result * 10;
num = num / 10;
}
printf("result = %d\n", result);
}
return 0;
}
运行结果如下:
希望能有更加简便的方法,实现这个功能。