输出个数字并且判断是几位数,并且倒序输出。

 1 #include <stdio.h>
 2 #include <math.h>
 3 int main()
 4 {
 5     int num,place,indiv,ten,hundred,thousand,ten_thousand;
 6     printf("输入一个数\n");
 7     scanf("%d",&num);
 8     if(num>9999)
 9         place=5;
10     else if(num>999)
11         place=4;
12     else if(num>99)
13         place=3;
14     else if(num>9)
15         place=2;
16     else
17         place=1;// 几位数结果
18         printf("位数%d\n",place);
19         printf("每一个数字为\n");
20         ten_thousand=num/10000;
21         printf("%d\n",ten_thousand);
22         thousand=(num-ten_thousand*10000)/1000;
23         printf("%d\n",thousand);
24         hundred=(num-ten_thousand*10000-thousand*1000)/100;
25         printf("%d\n",hundred);
26         ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10;
27         printf("%d\n",ten);
28         indiv=num%10;
29         printf("%d\n",indiv);
30         switch(place)
31         {
32         case 5:
33             printf("反序数字为:\n");
34             printf("%d%d%d%d%d\n",indiv,ten,hundred,thousand,ten_thousand);break;
35         case 4:
36             printf("反序数字为:\n");
37             printf("%d%d%d%d\n",indiv,ten,hundred,thousand);break;
38         case 3:
39             printf("反序数字为:\n");
40             printf("%d%d%d\n",indiv,ten,hundred);break;
41         case 2:
42             printf("反序数字为:\n");
43             printf("%d%d\n",indiv,ten);break;
44         case 1:
45             printf("反序数字为:\n");
46             printf("%d\n",indiv);
47         }
48         return 0;
49 } 

 

posted @ 2018-11-15 15:20  郭宇航  阅读(696)  评论(0)    收藏  举报