Notice
Recent Posts
Recent Comments
Link
목록팩토리얼 (1)
To become a Fintech Specialist
팩토리얼(Factorial)
1. 정의 - 1부터 양의 정수 n까지의 정수를 모두 곱한 것 예) 0! = 1 , 2! = 1x2 = 2, 3!=1x2x3 = 6 2. 실습 # 팩토리얼 결과값을 출력 input_n = int(input('n 입력: ')) #반복문을 이용하는 경우 result = 1 for n in range (1, input_n+1): result *=n print('{} 팩토리얼_반복문이용 : {}'.format(input_n, result)) #재귀함수를 이용하는 경우 def factorial_fun(n): if n==1: return 1 return n*factorial_fun(n-1) print('{} 팩토리얼_재귀함수이용:{}'.format(input_n, factorial_fun(input_n)))
연습노트/프로그래밍
2022. 3. 3. 14:56