Skip to content

Commit 715d795

Browse files
Merge pull request #58 from ragupathi09/master
Create Factorial_recursion.cpp
2 parents 5ba4dc3 + f7f7f0e commit 715d795

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

C++/Factorial_recursion.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int factorial(int);
5+
6+
int main() {
7+
int n, result;
8+
9+
cout << "Enter a non-negative number: ";
10+
cin >> n;
11+
12+
result = factorial(n);
13+
cout << "Factorial of " << n << " = " << result;
14+
return 0;
15+
}
16+
17+
int factorial(int n) {
18+
if (n > 1) {
19+
return n * factorial(n - 1);
20+
} else {
21+
return 1;
22+
}
23+
}

0 commit comments

Comments
 (0)