1073 A+B的m进制

 1 // Test1073-A+B的M进制.cpp: 定义控制台应用程序的入口点。
 2 //
 3 
 4 #include "stdafx.h"
 5 
 6 void ten_to_n(int num, int n)
 7 {
 8     int temp = 0;
 9     int list[20] = {};
10     int index = 0;
11     while (num > 0)
12     {
13 
14         //printf("%d", sum_ab);
15         temp = num % n;
16         //printf("%d %d\n", num, temp);
17         num /= n;
18         list[index++] = temp;
19 
20     }
21     for (int i = index - 1; i >= 0; i--)
22         printf("%d", list[i]);
23     printf("\n");
24 }
25 
26 int main()
27 {
28     int step;
29     while (1)
30     {
31         scanf_s("%d", &step);
32         if (step != 0)
33         {
34             int numa, numb, sum_ab;
35             scanf_s("%d %d", &numa, &numb);
36             sum_ab = numa + numb;
37             //8进制
38 
39             ten_to_n(sum_ab, step);
40         }
41         else break;
42     }
43 
44     return 0;
45 }

猜你喜欢

转载自www.cnblogs.com/kongchung/p/9330554.html
今日推荐