We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c90362c commit 137f77eCopy full SHA for 137f77e
fibonacci-rec.cpp
@@ -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