问答详情
源自:4-3 分支结构之多重if-else语句

求四位数得倒着输出

求大神解答


提问者:慕田峪3273735 2019-10-14 21:18

个回答

  • qq_慕先生1136314
    2019-10-18 09:22:48

    #include <stdio.h>
    void main()
    {
        int x, a, b, c, f, z,sum;
        printf ("input x");
        scanf ("%d", &x);
        a = x / 1000;
        f = x % 10;
        b = (x - a * 1000) / 100;
        c = (x - a * 1000 - b * 100) / 10;
        z = f * 1000 + c * 100 + b * 10 + a * 1;
        sum = a + b + c + f;
        printf("a=%d, b=%d, c=%d, f=%d, z=%d, sum=%d",a, b, c, f, z,sum);
    }

  • Stuart_千夜
    2019-10-16 19:33:19

    核心思想是求出四位数的各位数,再用printf进行倒着输出