GENERATE AND PRINT FIRST N FIBONACCI NUMBERS


c program to generate, print fibonacci series

This program generates Fibonacci series without recursion. You can print as many number of terms of series as desired.

C code

#include<stdio.h>
#include<conio.h>
 
main()
{
   int n, first = 0, second = 1, next, c;
 
   printf("Enter the number of terms ");
   scanf("%d",&n);
 
   printf("First %d terms of fibonacci series are :-\n",n);
 
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }
 
   getch();
   return 0;
}
Output:

fibonacci series

Comments

Popular posts from this blog