문제/백준_자바스크립트

66. 10872 (팩토리얼)

sm_hope 2022. 6. 6. 07:54
let input = require("fs").readFileSync(0).toString().split(" ");

const factorial = (N) => {
  if (N === 1 || N === 0) return 1;
  else return N * factorial(N - 1);
};

console.log(factorial(parseInt(input[0])));

재귀함수 이용

https://smhope.tistory.com/183

 

재귀함수

정의 하나의 함수에서 자기 자신을 다시 호출해 작업을 수행하는 방식으로 주어진 문제를 푸는 방법 화면 안에 화면이 있고 그 화면 안에 화면이 있으며 그 안에 ..... => 함수를 호출하고 다시 자

smhope.tistory.com