-
Notifications
You must be signed in to change notification settings - Fork 0
/
wuweishu.c
62 lines (60 loc) · 1.82 KB
/
wuweishu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "stdio.h"
#include "math.h"
/*
给出已过不多于5位的正整数,要求:
1)求出它是几位数;
2)分别输出每一位数字;
3)按逆序输出个位数字,例如袁术是321,应输出123。
*/
int main(int argc, char const *argv[])
{
int num,indiv,ten,hundred,thousand,ten_thousand,place;
//分别代表各位,十位,百位,千位,万位和位数
printf("请输入一个正整数(0-99999):\n");
scanf("%d",&num);
if(num>9999)
place = 5;
else if(num>999)
place = 4;
else if (num > 99)
place = 3;
else if (num > 9)
place = 2;
else
place = 1;
printf("位数: %d\n",place );
printf("每位数字为:\n");
// ten_thousand = num / 10000;
// thousand = (int)(num -ten_thousand * 10000)/1000;
// hundred = (int)(num-ten_thousand*1000-thousand*1000)/100;
// ten = (int) (num - ten_thousand*10000 -thousand*1000-hundred*100)/10;
// indiv = (int)(num -ten_thousand*10000 - thousand*1000-hundred*100-ten*10);
ten_thousand = num / 10000;
thousand = (int)(num % 10000)/1000;
hundred = (int)(num%1000)/100;
ten = (int) (num % 100)/10;
indiv = (int)(num % 10);
switch (place){
case 5 : printf("%d,%d,%d,%d,%d\n",ten_thousand,thousand,hundred,ten,indiv);
printf("\n 反序数字为:");
printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,ten_thousand);
break;
case 4 : printf("%d,%d,%d,%d\n",thousand,hundred,ten,indiv);
printf("\n 反序数字为:");
printf("%d%d%d%d\n",indiv,ten,hundred,thousand);
break;
case 3 : printf("%d,%d,%d\n",hundred,ten,indiv);
printf("\n 反序数字为:");
printf("%d%d%d\n",indiv,ten,hundred);
break;
case 2 : printf("%d,%d\n",ten,indiv );
printf("\n 反序数字为:");
printf("%d%d\n",indiv,ten);
break;
case 1 : printf("%d\n",indiv );
printf("\n 反序数字为:");
printf("%d\n",indiv);
break;
}
return 0;
}