Print the Fibonacci Series

Numbers of Fibonacci sequence are known as Fibonacci numbers. First few numbers of 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, For example 8 = 3 + 5 (addition of 3, 5). Print the Fibonacci Series up to the number of terms entered by the user.

/*
Print the Fibonacci Series
Shaswat Saxena
09/11/2017
*/
#include <stdio.h>
#include <conio.h>
void main ()
{
  int i,num,a,b,fib;
  clrscr();
  a=0;
  b=1;
  printf("Please enter the number of terms to be displayed (minimum 2)\n");
  scanf("%d", &num);
  printf("The Fibonacci Series is : \n");
  //First 2 numbers in the Series
  printf("%d\n%d\n",a,b);
  // Calculate Fibonacci Series
  for (i=2;i<num;i++) {
    fib=a+b;
    printf("%d\n",fib);
    a=b;
    b=fib;
  }
  getch();
}

Output

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for subscribing.

Something went wrong.

Recommended for You  Check for Strong Number

Leave a Reply

Close Menu