Skip to content

Commit

Permalink
Factorial of number using recursion added
Browse files Browse the repository at this point in the history
aalok28 committed Oct 19, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent dd366fc commit f8db6bd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CPP/Factorial of number using recursion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
using namespace std;

int factorial(int n);

int main()
{
int n;

cout << "Enter a positive integer: ";
cin >> n;

cout << "Factorial of " << n << " = " << factorial(n);

return 0;
}

int factorial(int n)
{
if (n > 1)
return n * factorial(n - 1);
else
return 1;
}

0 comments on commit f8db6bd

Please sign in to comment.