๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 10872๋ฒˆ - ํŒฉํ† ๋ฆฌ์–ผ

by dkswnkk 2021. 10. 25.
 

10872๋ฒˆ: ํŒฉํ† ๋ฆฌ์–ผ

0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜ N์ด ์ฃผ์–ด์ง„๋‹ค. ์ด๋•Œ, N!์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

#include <iostream>

using namespace std;
int sum = 1;
int factorial(int N) {
    if (N == 0) {
        cout << sum;
        return 1;
    }
    else { 
        sum *= N;
        return factorial(N - 1);
    }
    }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    factorial(N);
}

๋Œ“๊ธ€