您的位置:首页 > 其它

利用栈实现十进制到二进制的转换输出

2017-09-12 12:50 399 查看
#include <iostream>
#include<queue>
#include <string>
#include <stack>
using namespace std;
int main(){
int n;
stack<int> a;
while (1){
cin >> n;
string s;
while (n){
a.push(n % 2 );
n = n / 2;
}
while (!a.empty()){
cout << a.top() << ' ';
a.pop();
}
cout << endl;
}

}

输出结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐