Fibonacci Series Using C Program

0
931

Fibonacci Series Using C Program

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

#include<stdio.h>
 
int main()
{
   int n, number1 = 0, number2 = 1, next, i;
 
   printf("Enter the number of terms\n");
   scanf("%d",&n);
 
   printf("First %d terms of Fibonacci series are :-\n",n);
 
   for ( i = 0 ; i < n ; i++ )
   {
      if ( i <= 1 )
         next = i;
      else
      {
         next = number1 + number2;
         number1 = number2;
         number2 = next;
      }
      printf("%d\n",next);
   }
 
   return 0;
}

Leave a Reply