一、实现代码
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout << "输入一个整数:";
int num = 0;//定义一个十进制的数,程序使用
cin >> num;
int num1 = num;//输出使用
cout << endl;
cout << "输入你要转换的进制:";
int system = 0;//需要转换的进制
cin >> system;
cout << endl;
vector<int> Remainder;//定义vetor容器记录余数
while (num > 0)
{
Remainder.push_back(num % system);//记录余数
num = num / system;
}
cout << "十进制的" << num1 << "的" << system << "进制的数:";
//反向迭代器reverse_iterator,从rbegin(=end)到rend(=begin-1)反向遍历
vector<int>::reverse_iterator it;
for (it = Remainder.rbegin(); it != Remainder.rend(); it++)
cout << *it;
return 0;
}
如有不足之处,还望指正 1。
如果对您有帮助可以点赞、收藏、关注,将会是我最大的动力 ↩︎