백준 10872번: 팩토리얼

Se0ng_1l·2022년 6월 28일
0

팩토리얼 함수를 만들어 재귀함수를 호출하여 결과를 내는 문제

#include <iostream>
using namespace std;

int factorial(int n){
    if(n == 1 || n == 0)
        return 1;
    else
        return factorial(n - 1) * n;
}

int main()
{
    int n = 0;
    cin >> n;
    cout << factorial(n) << endl;
}
profile
치타가 되고 싶은 취준생

0개의 댓글