Algorithm/문제로 풀어보는 알고리즘 프로그래밍

    [Algorithm] Factorial Function

    [Algorithm] Factorial Function

    1. 팩토리얼 계산하기 - n!은 1부터 n까지의 자연수를 모두 곱한 것이다. [예시] 3!=1x2x3=6 6!=1x2x3x4x5x6=720 으로 예를 들 수 있다. 정의를 하자면 다음과 같이 정의할 수 있다. [식] n! = 1x2x3x...xn JAVA코드로 정의하면 다음과 같다 public class Main { public static void main(String[] args) { System.out.println(factorial(10)); System.out.println(factorial2(10)); } static int factorial(int n) { int r = 1; for (int i = 2; i