输入小于八位的数然后逆序输出

23456->65432

主要方法

 result = result + m % 10;//123%10=3 32 321
   m = m / 10;//12 1 0
   result = result * 10;//30 36 320 3210

 1 //23456->65432 而且不能超过8位
 2 
 3 //2017.3.7
 4 
 5 #include <stdio.h>
 6 #include <stdlib.h>
 7 
 8 int main()
 9 {
10     int m = 0;
11     int count = 0;//计算位数
12     printf("请输入一个整数
");
13     scanf_s("%d", &m);
14 
15     int t = m;//备份 因为下面计算位数的时候会导致原来的数值位0
16     while (t)
17     {
18         count++;//统计位数
19         t = t / 10;
20     }
21     //次循环结束时候M为0
22     if (count > 8)
23     {
24         printf("输入整数不能超过8位
");
25     }
26     else
27     {
28         int result = 0;
29         while (m>0)
30         {
31             result = result + m % 10;//123%10=3 32 321
32             m = m / 10;//12 1 0
33             result = result * 10;//30 36 320 3210
34         }
35         result = result / 10;
36         printf("%d", result);
37     }
38 
39     system("pause");
40     return 1;
41 }

原文地址:https://www.cnblogs.com/lanjianhappy/p/6533435.html