#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    // 求出它是几位数
    int digit = 0, temp = n;
    while (temp > 0) {
        digit++;
        temp /= 10;
    }
    printf("它是%d位数\n", digit);
    // 分别打印出每一位数字
    printf("每一位数字是:");
    int i;
    for (i = 0; i < digit; i++) {
        int d = n % 10;
        n /= 10;
        printf("%d ", d);
    }
    printf("\n");
    // 按逆序打印出各位数字
    printf("逆序输出是:");
    while (digit > 0) {
        int d = n % 10;
        n /= 10;
        printf("%d ", d);
        digit--;
    }
    printf("\n");
    return 0;
}
C语言实现正整数的位数、数字提取和逆序输出

原文地址: https://www.cveoy.top/t/topic/l3rE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录