forked from AllAlgorithms/cpp
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorial.cpp
More file actions
Latest commit
24 lines (20 loc) · 412 Bytes
/
Copy pathfactorial.cpp
File metadata and controls
24 lines (20 loc) · 412 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* Factorial
Author: Pablo Trinidad <github.com/pablotrinidad>
*/
#include<bits/stdc++.h>
usingnamespacestd;
intfactorial(int n) {
if (n <= 0) {
return1;
} else {
return n * factorial(n - 1);
}
}
intmain() {
int n;
cout << "Enter an integer n to compute its factorial: ";
cin >> n;
int r = factorial(n);
cout << n << "! = " << r << endl;
return0;
}