Skip to content

Commit 105ad35

Browse files
committed
renamed from q2.c
1 parent 5789cf5 commit 105ad35

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+
//WAP to calculate a term of Fibonacci series using a recursive function.
2+
3+
#include <stdio.h>
4+
5+
int fibonacci(int n);
6+
7+
int main() {
8+
int n;
9+
10+
printf("Enter a positive integer: ");
11+
scanf("%d", &n);
12+
13+
printf("The %dth term in the Fibonacci sequence is: %d\n", n, fibonacci(n));
14+
15+
return 0;
16+
}
17+
18+
int fibonacci(int n) {
19+
if (n == 0) {
20+
return 0;
21+
} else if (n == 1) {
22+
return 1;
23+
} else {
24+
return fibonacci(n-1) + fibonacci(n-2);
25+
}
26+
}

0 commit comments

Comments
 (0)