youngjaeLee1026 2022. 3. 14. 18:15

1. ๋ฌธ์ œ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-03-14 18 12 38

2. ์ž…์ถœ๋ ฅ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-03-14 18 12 51

3. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-03-14 18 13 07

4. ๋ฌธ์ œ ์„ค๊ณ„

  1. ํŒฉํ† ๋ฆฌ์–ผ์€ ๊ท€๋‚ฉ์  ์ •์˜์— ์˜ํ•ด, f(0) = 1, f(n)! = n * f(n - 1)!
  2. ๊ธฐ์ €์กฐ๊ฑด๊ณผ ์‹์„ ์ •ํ™•ํ•˜๊ฒŒ ๊ตฌํ˜„ํ•จ์œผ๋กœ์จ ์žฌ๊ท€ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Œ

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()

 

์ „์ฒด์ฝ”๋“œ๋Š” ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.