Settings | Sign in | Sign up

There is currently 1 post.

【試題】特殊迴文數

Floor 1 巨大八爪鱼 3/3/16 17:46
#include <stdio.h>

int main()
{
    int n, num;
    int a, b, c, d, e, f;
    scanf("%d", &n);
    for (num = 10000; num <= 99999; num++)
    {
        a = num / 10000;
        b = num % 10000 / 1000;
        c = num % 1000 / 100;
        d = num % 100 / 10;
        e = num % 10;
        if (a == e && b == d && a + b + c + d + e == n)
            printf("%d\n", num);
    }
    for (; num <= 999999; num++)
    {
        a = num / 100000;
        b = num % 100000 / 10000;
        c = num % 10000 / 1000;
        d = num % 1000 / 100;
        e = num % 100 / 10;
        f = num % 10;
        if (a == f && b == e && c == d && a + b + c + d + e + f == n)
            printf("%d\n", num);
    }
    return 0;
}

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.