forked from Annex5061/java-algorithms
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackfest.cpp
More file actions
Latest commit
25 lines (19 loc) · 402 Bytes
/
Copy pathHackfest.cpp
File metadata and controls
25 lines (19 loc) · 402 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
25
// Factorial of n = 1*2*3*...*n
#include<iostream>
usingnamespacestd;
intfactorial(int);
intmain() {
int n, result;
cout << "Enter a non-negative number: ";
cin >> n;
result = factorial(n);
cout << "Factorial of " << n << " = " << result;
return0;
}
intfactorial(int n) {
if (n > 1) {
return n * factorial(n - 1);
} else {
return1;
}
}