Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- void convert(int m){
- if (m > 0){
- convert(m/2);
- cout << m%2;
- }
- }
- void binary_stk(int m){
- stack<int> s;
- while (m > 0){
- s.push(m%2);
- m = m/2;
- }
- while(!s.empty()){
- cout << s.top();
- s.pop();
- }
- }
- int main(){
- int m;
- cout << "m = ";
- cin >> m;
- convert (m); cout << endl;
- binary_stk (m);
- }
Advertisement
Add Comment
Please, Sign In to add comment