팩토리얼
문제 설명
0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 정수 N(0 ≤ N ≤ 12)이 주어진다.
출력
첫째 줄에 N!을 출력한다.

Python 코드
def factorial(n): result = 1 if n > 0: result = n * factorial(n-1) return result n = int(input()) print(factorial(n))
* 참고 링크 : https://ooyoung.tistory.com/114
C++ 코드
#include <cstdio> int factorial(int n) { if(n <= 1) return 1; return n * factorial(n-1); } int main() { int num; scanf("%d",&num); printf("%d",factorial(num)); }
* 참고 링크 : https://cryptosalamander.tistory.com/36
출처
'코딩테스트 > 백준 알고리즘' 카테고리의 다른 글
[백준 알고리즘] 10162번 전자레인지_그리디알고리즘 (0) | 2022.03.12 |
---|---|
[백준 알고리즘] 10829번 이진수 변환 (0) | 2022.02.25 |
[백준 알고리즘] 15829번 Hashing (0) | 2022.02.18 |
[백준 알고리즘] 2606번 바이러스 (0) | 2022.02.14 |
[백준 알고리즘] 1260번 DFS와 BFS (0) | 2022.02.14 |