Factorial

Problem

Enter a natural number N to get the value of N!. N! = n(n-1)(n-2)2*1. If N=5 then 5!=54321=120.

input

In the first line, the natural number N (3<=n<=10) is entered.

5

output

Print the N factorial value on the first line.

120

Solution

plus

function solution(n) {
	let answer = 1;
	function DFS(l) {
		if (l > n) return;

		answer *= l;
		DFS(l + 1);
	}
	DFS(1);
	return answer;
}

subtract

function solution(n) {
	let answer;
	function DFS(n) {
		if (n === 1) return 1;
		else return n * DFS(n - 1);
	}
	answer = DFS(n);
	return answer;
}