10진수 N이 입력되면 2진수로 변환하여 출력하는 프로그램을 작성하세요. 단 재귀함수를 이용 해서 출력해야 합니다.
import sys
sys.stdin=open("input.txt","rt")
# n,m = map(int,input().split())
# n = int(input())
# arr = list(map(int,input().split()))
def DFS(x=0):
if x==0:
return
else:
DFS(x//2)
print(x%2,end='')
if __name__ =="__main__":
n = int(input())
DFS(n)
# res = ''
# i = 1
# while True:
# if n-i*2<0:
# break
# i *=2
# a= i
# v=n
# while a >0:
# if v-a >=0:
# res+='1'
# v-= a
# else:
# res+='0'
# a//=2
# print(res)'코테연습 > python' 카테고리의 다른 글
| 부분집합 구하기(DFS) (0) | 2026.05.12 |
|---|---|
| 이진트리 순회(깊이우선탐색) (0) | 2026.05.11 |
| 최대힙 (0) | 2026.05.07 |
| 최소힙 (0) | 2026.05.06 |
| Anagram(아나그램) 스택 (0) | 2026.05.05 |