본문 바로가기

카테고리 없음

[C++]재귀호출을 이용한 2진수 변환

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
 
void Convert2Bin(int dec)
{
    if (dec <= 0)
        return;
 
    Convert2Bin(dec / 2);
 
    cout << dec % 2;
}
int main()
{
    Convert2Bin(13);
 
    cout << "\n";
    return 0;
 
}
cs