Recursive Factorial

Lab C++ Intermediate 20 points

Write a recursive unsigned long long fact(int n) and print it for n 0–20.

Input

One integer.

Output

n!

Example

Input

5

Output

120
Sample input available Sample output available
Editor
C++

Hints

Base case: fact(0) = fact(1) = 1.

Solution explanation

Each call waits for the smaller call, then multiplies.

Show solution
#include <iostream>
using namespace std;

unsigned long long fact(int n) {
    return n <= 1 ? 1 : n * fact(n - 1);
}

int main() {
    int n;
    cin >> n;
    cout << fact(n) << "\n";
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD