B1022 D进制的A+B (20 分)

进制转换通式

  1. a是待转换的数字,d是需要转换的进制,z[num]是转换后存放的地方。

  2. do{
          
          
        z[num++] = a % d;
        a = a / d;
    }while(a != 0);
    
    for(int i = num-1; i >= 0; i--){
          
          
        cout << z[i];
    }
    
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
    
    
	int a, b, d, num = 0;
	cin >> a >> b >> d;
	int z[31];
	a = a + b;
	
	do{
    
    
		z[num++] = a % d;
		a = a / d;
	}while(a != 0);
	
	for(int i = num-1; i >= 0; i--){
    
    
		cout << z[i];
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/alovelypeach/article/details/113971352