Skip to content

Commit

Permalink
Merge pull request #488 from geeky01adarsh/master
Browse files Browse the repository at this point in the history
Added two recursion programs
  • Loading branch information
rishabhrathore055 authored Oct 3, 2021
2 parents cc64196 + 39e7b10 commit e20f494
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions Contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@
<a class="box-item" href="https://github.com/SamarthSawhney"><spann>Samarth Sawhney</span></a>
<a class="box-item" href="https://github.com/highflyer910"><span>Thea M.</span></a>
<a class="box-item" href="https://github.com/nyctonio"><span>Ritesh Kumar</span></a>
<a class="box-item" href="https://github.com/geeky01adarsh"><span>Adarsh Navneet Sinha</span></a>



Expand Down
19 changes: 19 additions & 0 deletions Program's_Contributed_By_Contributors/Recursion/factorial_n.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Find the factorial of n
#include <iostream>
using namespace std;

int factorial(int n)
{
if (n == 0)
return 1;
int ans = factorial(n - 1);
return n * ans;
}

int main(int argc, char const *argv[])
{
int n;
cin >> n;
cout << factorial(n) << endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// find the nth term of fibonacci series using recursion
#include<iostream>
using namespace std;

int fibonacci(int n){
if(n==0)
return 0;
else if(n==1)
return 1;
int ans = fibonacci(n-1)+fibonacci(n-2);
return ans;
}

int main(int argc, char const *argv[])
{
int n;
cin>>n;
cout<<fibonacci(n)<<endl;
return 0;
}

0 comments on commit e20f494

Please sign in to comment.