Skip to content

Commit ddddc4f

Browse files
committed
Create recursion.c
1 parent d183628 commit ddddc4f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Fibonacci/recursion.c

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Simple C program to print the first n terms of fibonacci series */
2+
/* ps. don't use recursion for fibonacci!!! */
3+
4+
#include <stdio.h>
5+
6+
int fib(int n)
7+
{
8+
if (n == 1)
9+
return 0;
10+
if (n == 2)
11+
return 1;
12+
return fib(n - 1) + fib(n - 2);
13+
}
14+
15+
int main()
16+
{
17+
int n = 10;
18+
printf("The first %d terms of fibonacci series are:\n", n);
19+
20+
for (int i = 1; i <= n; i++)
21+
printf("%d\n", fib(i));
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)