Posted By:
23 Jun, 2013 1:06 pm PDT

Fibonacci Series in C

How to print the Fibonacci series?
Attachment:None


First few numbers of Fibonacci series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two terms in sequence every other term is the sum of two previous terms, i.e. to get the 8th number we have to add the 6th and 7th numbers. So we get 13. We use following code to get the series

 

 

#include<stdio.h>

#include<conio.h> 

int main()

{

   int n, c, first = 0, second = 1, next;

    printf("Enter the number of terms of Fibonacci series you want");

   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("\t%d",next);

   }

   getch();

} 

 

 

Please see the video for more details.

Was it useful?  



To make the code easily understandable , please watch the above video and follow the program.

#include<stdio.h>

int main()

{

  int count, n, t1=0, t2=1, display=0;

  printf("Enter number of terms: ");

  scanf("%d",&n);

  printf("Fibonacci Series: %d+%d+", t1, t2);

 

/* Displaying first two terms */

  count=2;   

 

/* count=2 because first two terms are already displayed. */

  while(count<n) 

  {

      display=t1+t2;

      t1=t2;

      t2=display;

      ++count;

      printf("%d+",display);

  }

  return0;

}


Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud