Skip to content

Commit 137f77e

Browse files
authored
filre for fibonacci
recursion
1 parent c90362c commit 137f77e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

fibonacci-rec.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*C program to print fibonacii series till N terms.*/
2+
3+
#include <stdio.h>
4+
5+
//function to print fibonacii series
6+
void getFibonacii(int a,int b, int n)
7+
{
8+
int sum;
9+
if(n>0)
10+
{
11+
sum=a+b;
12+
printf("%d ",sum);
13+
a=b;
14+
b=sum;
15+
getFibonacii(a,b,n-1);
16+
}
17+
}
18+
int main()
19+
{
20+
int a,b,sum,n;
21+
int i;
22+
23+
a=0; //first term
24+
b=1; //second term
25+
26+
printf("Enter total number of terms: ");
27+
scanf("%d",&n);
28+
29+
printf("Fibonacii series is : ");
30+
//print a and b as first and second terms of series
31+
printf("%d\t%d\t",a,b);
32+
//call function with (n-2) terms
33+
getFibonacii(a,b,n-2);
34+
printf("\n");
35+
return 0;
36+
}

0 commit comments

Comments
 (0)