一、运行结果;
二、源代码;
cs
# define _CRT_SECURE_NO_WARNINGS
# include <stdio.h>
int main()
{
//初始化变量值;
int number = 0;
int i = 1;
int m = 0;
int z = 0;
int z1 = 0, z2 = 0, z3 = 0, z4 = 0;
//提示用户;
printf("请输入一个不多于5位的正整数:");
//获取用户输入的数据;
scanf("%d", &number);
//循环获取数据
while (number > 99999 || number < 0)
{
//提示用户
printf("您输入的数据不满足条件!!!!\n");
printf("请输入一个不多于5位的正整数:");
//获取用户输入的数据;
scanf("%d", &number);
}
//赋值;
m = number;
//循环判断number的位数;
while (m > 9)
{
//运算;
m = m / 10;
//更改变量的值;
i++;
}
//输出结果;
printf("%d是%d位数!!!!\n", number, i);
//判断每位的数据值,并分别输出每一位数值;
switch (i)
{
case 5:
//运算;
z1 = number / 10000;
number = number % 10000;
//输出数值;
printf("万位为%d\n", z1);
case 4:
//运算;
z2 = number / 1000;
number = number % 1000;
//输出数值;
printf("千位为%d\n", z2);
case 3:
//运算;
z3 = number / 100;
number = number % 100;
//输出数值;
printf("百位为%d\n", z3);
case 2:
//运算;
z4 = number / 10;
number = number % 10;
//输出数值;
printf("十位为%d\n", z4);
case 1:
//输出数值;
printf("个位为%d\n", number);
}
//倒序输出每位的数据值;
switch (i)
{
case 1:
//输出;
printf("倒序为:%d", number);
break;
case 2:
//输出;
printf("倒序为:%d%d", number, z4);
break;
case 3:
//输出;
printf("倒序为:%d%d%d", number, z4, z3);
break;
case 4:
//输出;
printf("倒序为:%d%d%d%d", number, z4, z3, z2);
break;
case 5:
//输出;
printf("倒序为:%d%d%d%d%d", number, z4, z3, z2, z1);
break;
}
return 0;
}
三、N-S流程图;