PAT乙级1012-D进制的A+B (20)



 
//D进制的A+B (20)
#include<iostream>
#include<stdlib.h>
#include<string>

using namespace std;
string conversion_number(int sum, int D )
{
           string str = "" ;  //用string类型返回
           while (sum )  //模除求得进制
          {
                   str = ( char)(sum %D + '0') + str; 
                    sum /= D ;
          }
           return str;
}
int main()
{
           int A = 0, B = 0;
           int D = 0;
          cout << "请输入A,B,D的值" << endl;;
          cin >> A >> B >> D; 

           int sum = A + B;
           string str = conversion_number(sum, D);
          cout << str;

          system( "pause");
           return 0;
}



PAT乙级1012-D进制的A+B (20)_第1张图片



你可能感兴趣的:(PAT乙级1012-D进制的A+B (20))