十进制转任意进制数

//十进制转任意进制
#include <iostream>
#include <stack>
using namespace std;

int main()
{
    int T;
    int n, a, p;
    cin >> T;
    while (T--)
    {
        stack<int> s; 
        //n 为十进制,p为要转换的进制
        cin >> n >> p;
        while (n)
        {
            a = n % p;
            s.push(a);
            n /= p;
        }
        while (!s.empty())
        {
            cout << s.top();
            s.pop();
        }
        cout << endl;
    }
    system("pause");
    return 0;
}

运行测试:

猜你喜欢

转载自www.cnblogs.com/clwsec/p/11565447.html