이진수 출력 (재귀)

이세진·2022년 4월 15일
0

코테준비

목록 보기
43/87

생성일: 2022년 1월 29일 오후 6:18

구현 코드

# 이진수 출력(재귀)
import sys
#sys.stdin = open("input.txt", "rt")
n = int(input())
res = []

def convertToBinary(n, res):
    if n > 1:
        remainder = n % 2
        n = n // 2
        convertToBinary(n, res) # 재귀
        res.append(remainder)
        return res
    else:
        res.append(n)
        return

res = convertToBinary(n, res)
for x in res:
    print(x, end='')
profile
나중은 결코 오지 않는다.

0개의 댓글