youngjaeLee1026
2022. 3. 14. 18:15
1. ๋ฌธ์
2. ์ ์ถ๋ ฅ
3. ์ ์ถ๋ ฅ ์์
4. ๋ฌธ์ ์ค๊ณ
- ํฉํ ๋ฆฌ์ผ์ ๊ท๋ฉ์ ์ ์์ ์ํด, f(0) = 1, f(n)! = n * f(n - 1)!
- ๊ธฐ์ ์กฐ๊ฑด๊ณผ ์์ ์ ํํ๊ฒ ๊ตฌํํจ์ผ๋ก์จ ์ฌ๊ทํจ์๋ฅผ ๊ตฌํํ ์ ์์
5. ์ ์ฒด ์ฝ๋
//
// main.swift
// Factorial
//
// Created by ์ด์์ฌ on 2022/03/14.
//MARK: - ํฉํ ๋ฆฌ์ผ
//MARK: - Framework
import Foundation
//MARK: - Function
func getFactorial(_ N: Int) -> Int {
return N == 0 ? 1 : N * getFactorial(N - 1)
}
func solution() -> Void {
//MARK: - Input
guard let N: Int = Int(readLine() ?? "0") else { return }
var factorial: Int = 0
//MARK: - Process
factorial = getFactorial(N)
//MARK: - Output
print(factorial)
}
solution()
์ ์ฒด์ฝ๋๋ ์ฌ๊ธฐ์์ ํ์ธํ ์ ์์ต๋๋ค.