#include <iostream> #include <stdio.h> #include <stack> #include <assert.h> using namespace std; int main() { char digit[16] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; int num; cout << "待转换的数据:" ; cin >> num; cout <<"转换成进制数M: "; int m; cin >>m; assert((m>1)&&(m<=16)); stack<char> stk; char remain; while (num!=0)//转成M进制 { remain = digit[num%m]; stk.push(remain); num/= m; } cout <<"结果: ";//输出结果 while(!stk.empty()) { cout <<stk.top(); stk.pop(); } cout <<endl; system("pause"); return 0; }