SNOWSD

导航

c语言的学习路程———整数分解

#include<stdio.h>

int main() {
    int a;
    scanf_s("%d", &a);

    int x = a;

    int count = 0;
    int mask = 1;

    while (a > 9) {
        a /= 10;
        mask *= 10;
        count++;
    }

    printf("count=%d\n", count);
    printf("mask=%d\n", mask);


    do {
        int d = x / mask;
        printf("%d", d);
        if (mask > 0) {
            printf(" ");
        }
        x %= mask;
        mask /= 10;
    } while (mask > 0);

    printf("\n");

    return 0;
}

 

posted on 2021-01-08 20:17  SNOWSD  阅读(201)  评论(0编辑  收藏  举报