C program to Display Fibonacci series

 

C program for Fibonacci series

  1. The Fibonacci sequence is the series of numbers, in which each number is the sum of the two numbers that precede it.
  2. So the sequence goes : 0,1,1,2,3,5,8,13,21,34   and so on.
  3. The next number is found by adding up the two numbers before it :

  • 2 is found by adding  1 and 1 which is [1+1=2]
  • 34 is found by adding  13 and 21 which is [13+21=34]

About the discoverer of Fibonacci series

  1. Leonardo Pisano Bogollo discovered the Fibonacci series.
  2. Fibonacci was his nickname, which means the son of Bonacci.

C program to Display Fibonacci series 

    1.   #include<stdio.h>
    2.     int main()
    3.    {
    4.      int num1 = 0;
    5.      int num2 = 1;
    6.      int num3 = 0;
    7.      int i = 0;
    8.      int number = 0;
    9.       printf("Enter the number of fibonacci to be printed : ");
    10.       scanf("%d",&number);
    11.       printf("\n %d\n %d\n",num1,num2);
    12.         for(i = 2; i < number; ++i) 
    13.             {
    14.               num3 = num1+num2;
    15.               printf(" %d \n",num3);
    16.               num1 = num2;
    17.               num2 = num3;
    18.              }
    19.      return 0;
    20.      }

Post a Comment

0 Comments