Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags more
Archives
Today
Total
관리 메뉴

작은 지식주머니

백준 10872 팩토리얼 파이썬 본문

백준 python 기록

백준 10872 팩토리얼 파이썬

작지 2021. 11. 5. 17:41

백준 링크:https://www.acmicpc.net/problem/10872

 

10872번: 팩토리얼

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

www.acmicpc.net

 

 

두 가지 방법이 있다.

1. math 라이브러리를 이용.

import math

n = int(input())

print(math.factorial(n))

 

 

2. 재귀함수를 이용

n = int(input())

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

print(factorial(n))
Comments