https://www.acmicpc.net/problem/10872

 

10872번: 팩토리얼

0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오.

www.acmicpc.net

 

풀이 과정

1. python의 math 모듈 내의 factorial 함수 사용하기

import math

N = int(input())
print(math.factorial(N))

2. 팩토리얼의 정의에 따라 재귀 함수 구현하기

def factorial(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * factorial(n - 1)


N = int(input())
print(factorial(N))

소스 코드

풀이 과정 참조

 

+ Recent posts