Skip to content

Commit 937b393

Browse files
authored
Merge pull request #1347 from priyalbhatewara123/dev
Find nth term in fibonacci series using recursion
2 parents 6417c1f + 1b4a6df commit 937b393

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Problem Statement:
3+
Find nth term in fibonacci series using recursion
4+
*/
5+
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
9+
int fibonacci(int n) {
10+
11+
//base case
12+
if (n == 0 or n == 1) {
13+
return n;
14+
}
15+
16+
return (fibonacci(n - 1) + fibonacci(n - 2));
17+
}
18+
19+
20+
int main() {
21+
22+
int n; cin >> n;
23+
cout << fibonacci(n);
24+
25+
return 0;
26+
}

0 commit comments

Comments
 (0)