#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int main()
{
long long n;
printf("输入一个整数:");
scanf("%lld", &n);
long long m = n;
//统计数字位数
int count = 0;
do
{
count++;
n /= 10;
} while (n != 0);
printf("数字位数:%d\n", count);
//顺序输出
n = m;
int power = pow(10, count - 1);
printf("顺序输出:");
if (n < 0)
{
printf("- ");
n = -n;
}
do
{
printf("%d ", n / power);
n %= power;
power /= 10;
} while (n != 0);
printf("\n");
//逆序输出
n = m;
printf("逆序输出:");
if (n < 0)
{
printf("- ");
n = -n;
}
do
{
printf("%d ", n % 10);
n /= 10;
} while (n != 0);
printf("\n");
return 0;
}
C语言 统计数字位数,顺序输出和逆序输出
于 2023-10-20 21:45:22 首次发布