For Advertisements on this blog Contact Us at developgram@gmail.com or +91-9923438816

Simple Programming Tutorials For Beginners

Sunday, December 11, 2016

Fibonacci Series

/*
Summary: Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,...
*/

#include <stdio.h>
int main()
{
 int count, n, t1=0, t2=1, display=0;

 printf("Enter number of terms: ");
 scanf("%d",&n);

 /* Displaying first two terms */
 printf("Fibonacci Series: %d+%d+", t1, t2);

 count=2;
 /* count=2 because first two terms are already displayed. */
 while (count<n) 
 {
 //add first two
  display=t1+t2;
 //set first no. value to second
  t1=t2;
 //set second no. value to result of addition
  t2=display;
 //increment count
  ++count;
  printf("%d+",display);
 }
 return 0;
}

No comments:

Post a Comment

SEARCH THIS BLOG