Fibonacci Series in C

The Fibonacci series is the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, so on.

In the above series, first term zero ‘0’ is added  with second term one ‘1’ and resultant will be the next term. And again second term is added with third term and resultant will be the next term and so on for n number of terms.

Below coding is the program for Fibonacci Series in C using function.

#include<stdio.h>
#include<conio.h>
void fib(int);
void main()
{
 int n;
 clrscr();
 printf("\n\nEnter the terms: ");
 scanf("%d",&n);
 fib(n);
 getch();
}
void fib(int x)
{
 int n,a,b,c,t,i;
 n=x;
 a=0;
 b=1;
 c=0;
 printf("\n\n%d",a);
 for(i=1;i<=n;i++)
 {
  c=a+b;
  printf("\n%d",c);
  t=a;
  a=c;
  b=t;
 }
}

In the above program, fib() is function which is call from main function and output will be displayed in the screen each time when term is added until the n number of term.

Leave a Reply