File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+
3
+ int term ;
4
+ int fibonacci (int prNo , int num );
5
+
6
+ void main ()
7
+ {
8
+ static int prNo = 0 , num = 1 ;
9
+ printf ("\n\n Recursion : Print Fibonacci Series :\n" );
10
+ printf ("-----------------------------------------\n" );
11
+
12
+ printf (" Input number of terms for the Series (< 20) : " );
13
+ scanf ("%d" , & term );
14
+ printf (" The Series are :\n" );
15
+ printf (" 1 " );
16
+ fibonacci (prNo , num );
17
+ printf ("\n\n" );
18
+ }
19
+
20
+ int fibonacci (int prNo , int num )
21
+ {
22
+ static int i = 1 ;
23
+ int nxtNo ;
24
+
25
+ if (i == term )
26
+ return (0 );
27
+ else
28
+ {
29
+ nxtNo = prNo + num ;
30
+ prNo = num ;
31
+ num = nxtNo ;
32
+ printf ("%d " , nxtNo );
33
+
34
+ i ++ ;
35
+ fibonacci (prNo , num ); //recursion, calling the function fibonacci itself
36
+ }
37
+ return (0 );
38
+ }
You can’t perform that action at this time.
0 commit comments