Skip to content

Commit

Permalink
백준/단계별: 10872 팩토리얼 (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunnnn committed Oct 13, 2023
1 parent b0d5ed0 commit bc7db7e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/baekjoon/step/combinatoric/PROB10872.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package baekjoon.step.combinatoric;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PROB10872 {
public static int factorial(int n) {
// base case
if(n == 0) {
return 1;
} else {
return n * factorial(n-1);
}
}

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(factorial(N));

}

}
15 changes: 15 additions & 0 deletions src/baekjoon/step/combinatoric/PROB10872.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 팩토리얼을 재귀함수로 짜보자


# 재귀함수
def factorial(N):
if N == 0:
return 1

return N * factorial(N-1)

# N 을 입력받자
N = int(input())

# 결과를 출력해보자
print(factorial(N))

0 comments on commit bc7db7e

Please sign in to comment.