알고리즘 풀이/백준

[백준][Java] 10872번 팩토리얼

배게 2018. 4. 21. 04:29
728x90

n! = n * (n-1) * (n-2) * ... * 2 * 1

팩토리얼 구현


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int input = sc.nextInt();
		int res=1;
		for(int i=input;i>=1;i--) {
			res*=i;
		}
		System.out.println(res);
	}
}