天天看點

利用棧實作進制轉換(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;
}
           

繼續閱讀