C Program for Fibonacci Series Using Recursion

0
727

C Program for Fibonacci Series Using Recursion

Note: Fibonacci Series: 0, 1, 1, 2, 3, 5, 8…

#include<stdio.h>
 
int Fibonacci(int);
 
main()
{
   int n, i, j = 0;
 
   scanf("%d",&n);
 
   printf("Fibonacci series\n");
 
   for ( i = 1 ; i <= n ; i++ )
   {
      printf("%d\n", Fibonacci(j));
      j++; 
   }
 
   return 0;
}
 
int Fibonacci(int n)
{
   if ( n == 0 )
      return 0;
   else if ( n == 1 )
      return 1;
   else
      return ( Fibonacci(n-1) + Fibonacci(n-2) );
} 

Leave a Reply