![[백준 알고리즘] 10872번 팩토리얼 (Python, Java)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fee2fOE%2FbtqCD7VCDWH%2FQuSiDt2RbmfJw324xf5iP0%2Fimg.png)
[백준 알고리즘] 10872번 팩토리얼 (Python, Java)언어, 알고리즘 공부/백준2020. 3. 10. 17:16
Table of Contents

<Python>
재귀로 푸는 방법
N = int(input())
def factorial(N):
if N <= 1:
return 1
return N * factorial(N-1)
print(factorial(N))
while문으로 푸는 방법
N = int(input())
factorial = 1
while N >0:
factorial *= N
N-=1
print(factorial)
<Java>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
System.out.println(fac(n));
}
public static int fac(int n){
if(n==1 || n==0)
return 1;
return n*fac(n-1);
}
}
▼ 링크
https://www.acmicpc.net/problem/10872
10872번: 팩토리얼
0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오.
www.acmicpc.net
반응형
'언어, 알고리즘 공부 > 백준' 카테고리의 다른 글
[백준 알고리즘] 1541번 잃어버린 괄호 (Python) (0) | 2020.03.10 |
---|---|
[백준 알고리즘] 10870번 피보나치 수 5 (Python) (0) | 2020.03.10 |
[백준 알고리즘] 11399번 ATM (Python) (0) | 2020.03.10 |
[백준 알고리즘] 1931번 회의실배정(Python) (0) | 2020.03.10 |
[백준 알고리즘] 11047번 동전 0 (Python) (0) | 2020.03.10 |
@쿠몬e :: ˚˛˚ * December☃ 。* 。˛˚
전공 공부 기록 📘
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!