天天看点

利用栈实现进制转换(c++)

将十进制转换为八进制

#include<iostream>
#include<stack>
using namespace std;
int main(){
	stack<int> p;
	int x;
	cout<<"请输入一个十进制的数字:";
	cin>>x;
	while(x){
		p.push(x%8);
		x/=8;
	}
	cout<<"该数字的八进制为:";
	while(!p.empty()){
		cout<<p.top();
		p.pop();
	} 
	return 0;
}
           

继续阅读