C Program to Print Fibonacci Series Using Recursion
A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
- //C program to print Fibonacci series using recursion
-
- #include<stdio.h>
-
- int Fibo(int);
-
- int main()
- {
- int a, i = 0, c;
- printf(" enter number of elements wanted :");
- scanf("%d",&a); // user input
- printf("Fibonacci series\n");
- for ( c = 1 ; c <= a ; c++ )
- {
- printf("%d\n", Fibo(i)); //calling the recursive function
- i++;
- }
-
- return 0;
- }
-
- int Fibo(int a) //recursive function Fibo
- {
- if ( a == 0 )
- return 0;
- else if ( a == 1 )
- return 1;
- else
- return ( Fibonacci(a-1) + Fibonacci(a-2) );
- }
Output
