十进制转十进制以下的其他进制

//十进制转十进制以下的其他进制
#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;
}

运行测试:

posted @ 2019-09-21 23:33  煊奕  阅读(121)  评论(0编辑  收藏  举报