0分求助啊大佬们/(ㄒoㄒ)/~~

P1307 [NOIP2011 普及组] 数字反转

ZJdog @ 2024-02-26 09:27:45

#include <stdio.h>

int main() {
    int n, a;
    int sum;
    scanf("%d", &n);
    if (n < 0) {
        n = -n;
        printf("-");
    }
    if (n % 10 == 0) {
        n = n / 10;
    }
    while (n != 0) {
        a = n % 10;
        n = n / 10;
        sum = sum * 10 + a;
    }
    printf("%d", sum);
    return 0;
}

by tang2010 @ 2024-02-26 09:52:17

@ZJdog 你的sum没有数值。让他等于零就可以过。


by tang2010 @ 2024-02-26 09:53:34

@ZJdog

 if (n % 10 == 0) {
        n = n / 10;
    }

这个删掉也一样


by ZJdog @ 2024-02-28 09:21:04

感谢大佬们!!!


|