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.

  1. //C program to print Fibonacci series using recursion
  2. #include<stdio.h>
  3. int Fibo(int);
  4. int main()
  5. {
  6. int a, i = 0, c;
  7. printf(" enter number of elements wanted :");
  8. scanf("%d",&a); // user input
  9. printf("Fibonacci series\n");
  10. for ( c = 1 ; c <= a ; c++ )
  11. {
  12. printf("%d\n", Fibo(i)); //calling the recursive function
  13. i++;
  14. }
  15. return 0;
  16. }
  17. int Fibo(int a) //recursive function Fibo
  18. {
  19. if ( a == 0 )
  20. return 0;
  21. else if ( a == 1 )
  22. return 1;
  23. else
  24. return ( Fibonacci(a-1) + Fibonacci(a-2) );
  25. }

Output

Output!