10进制转化为m进制

Posted zhanghua-322

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了10进制转化为m进制相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <stack>
using namespace std;
int main()

   int r, n;
   stack<int>s;
   cin >> n >> r;
   while (n)
   
      s.push(n % r);
      n /= r;
   
   while (!s.empty())
   
      switch (s.top())
    
    case 10:cout << ‘A‘; break;
    case 11:cout << ‘B‘; break;
    case 12:cout << ‘C‘; break;
    case 13:cout << ‘D‘; break;
    case 14:cout << ‘E‘; break;
    case 15:cout << ‘F‘; break;
    default:cout << s.top(); break;
    
    s.pop();
   
   return 0;

  

以上是关于10进制转化为m进制的主要内容,如果未能解决你的问题,请参考以下文章