Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- void binary(int m){
- if (m > 0){
- binary(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;
- binary(m); cout << endl;
- binary_stk(m);
- }
Advertisement
Add Comment
Please, Sign In to add comment