[codeup] 1902 : (재귀 함수) 1부터 n까지 역순으로 출력하기

SUNGJIN KIM·2022년 3월 9일
0

CODEUP

목록 보기
19/76
post-thumbnail

문제

https://codeup.kr/problem.php?id=1902&rid=0

정수 n부터 1까지 출력하는 재귀함수를 설계하시오.

이 문제는 반복문 for, while 등을 이용하여 풀수 없습니다.

입력

정수 n이 입력된다(1<=n<=200)

입력예시

10

출력

n부터 1까지 한 줄에 하나씩 출력한다.

출력예시

10
9
8
7
6
5
4
3
2
1

문제 풀이

이전에 풀었던 문제에서 print 위치를 변경해주면된다.

n = int(input())
def print_number(n):
    if n != 0:
        print(n)
        print_number(n-1)

print_number(n)
profile
#QA #woonmong

0개의 댓글