C program for Fibonacci Series upto a limited ranges.

Posted by Mangesh on March 16, 2018

/* Fibonacci Series */

Description :

The Fibonacci Sequence is the series of numbers : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
The next number is found by adding previous two numbers. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!

Logic :

Fibonacci Series is a series where nth number in the series in the sum of (n-1)th number and (n-2)th number if they exists. therefore,
nth number = (n-1)th + (n-2)th

Program :

#include<stdio.h>
#include<conio.h>
void main()
{
  int first = 0,second = 1,next,i,n;
  printf("Limit should be aleast 2.\n");
  printf("Enter the limit of number : ");
  scanf("%d",&n);
  printf("%d %d ",first,second);
  for(i=0;i<n-2;i++)
  {
    next = first + second;
    printf("%d ",next);
    first = second;
    second = next;
  }
  getch();
}

Output :

C program for fibonacci series` tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program to check whether given number is prime number or not.
2 C program for Fibonacci Series upto a limited ranges.
3 C program to find whether the number is Armstrong number or not.
4 C program to convert decimal number to octal number.
Latest Post
1 shubhanshu
2 test
3 C program for Breadth First Search.
4 C program for Depth First Search(DFS).
5 C for circular queue using linked list.