Skip to content

Commit 5659111

Browse files
Merge pull request #725 from gaurangvyas98/master
fibonacci.cpp using recursion
2 parents fa5dcb4 + 90d5afe commit 5659111

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

C++/recursion/fibonacci.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int fibonacci(int n)
6+
{
7+
if(n==0)
8+
return 0;
9+
if(n==1)
10+
return 1;
11+
int smallOutput1 = fibonacci(n-1);
12+
int smallOutput2 = fibonacci(n-2);
13+
return smallOutput1 + smallOutput2;
14+
}
15+
16+
int main()
17+
{
18+
int n;
19+
cin>>n;
20+
int output = fibonacci(n);
21+
cout<<output;
22+
}

0 commit comments

Comments
 (0)