• 코드:
​x
 
1
#include <iostream>
2
#include <stack>
3
using namespace std;
4
​
5
int main(void)
6
{
7
    int decimal = 123;
8
    stack<int> st;
9
    
10
    // 10진수를 2진수로 변환 
11
    do {
12
        st.push(decimal % 2);
13
        decimal /= 2;
14
    } while(decimal);
15
    
16
    // 스택의 모든 요소를 인출 
17
    while(!st.empty())
18
    {
19
        cout << st.top();
20
        st.pop();
21
    }
22
    return 0;
23
}
표준입력 & 실행옵션