Menu

Wednesday 2 March 2016

C Program for Fibonacci Series

#include<stdio.h>
#include<conio.h>
void main()
{
   int num, a = 0, b = 1, t, c;

   printf("Enter the number of terms\n");
   scanf("%d",&num);

   printf("Fibonacci series upto first %d terms :-\n",num);

   for ( c = 0 ; c < num ; c++ )
   {
      if ( c <= 1 )
         t = c;
      else
      {
         t = a + b;
         a = b;
         b = t;
      }
      printf("%d\n",t);
   }

   getch();
}

No comments:

Post a Comment