forked from dharmanshu1921/Java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiple.java
More file actions
Latest commit
25 lines (19 loc) · 402 Bytes
/
Copy pathMultiple.java
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() {
intn, result;
cout << "Enter a non-negative number: ";
cin >> n;
result = factorial(n);
cout << "Factorial of " << n << " = " << result;
return0;
}
intfactorial(intn) {
if (n > 1) {
returnn * factorial(n - 1);
} else {
return1;
}
}