Saturday, 28 April 2012

Program in C to Print the First n terms of the Fibonacci Series


#include<stdio.h>
#include<conio.h>
 
int main()
{
   int n, x = 0, y = 1, z, c;
 
   printf("Enter the number of terms\n");
   scanf("%d",&n);
 
   printf("\n %d terms of the Fibonacci Series are as follows,\n",n);
 
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         z = c;
      else
      {
         z = x + y;
         x = y;
         y = z;
      }
      printf("%d\n",z);
   }
   getch();
   return 0;
}

No comments:

Post a Comment