C Program to Fibonacci Sequence

A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.

Leonardo Bonacci (c. 1170 – c. 1250)—known as Fibonacci, and also Leonardo of Pisa, Leonardo Pisano Bigollo, Leonardo Fibonacci—was an Italian mathematician, considered to be "the most talented Western mathematician of the Middle Ages".

Fibonacci popularized the Hindu–Arabic numeral system to the Western World primarily through his composition in 1202 of Liber Abaci (Book of Calculation).[6] He also introduced to Europe the sequence of Fibonacci numbers which he used as an example in Liber Abaci.

Fibonacci sequence   Fibonacci number

19th century statue of Fibonacci in Camposanto, Pisa.
Liber Abaci posed, and solved, a problem involving the growth of a population of rabbits based on idealized assumptions. The solution, generation by generation, was a sequence of numbers later known as Fibonacci numbers. Although Fibonacci's Liber Abaci contains the earliest known description of the sequence outside of India, the sequence had been noted by Indian mathematicians as early as the sixth century.
In the Fibonacci sequence of numbers, each number is the sum of the previous two numbers. Fibonacci began the sequence not with 0, 1, 1, 2, as modern mathematicians do but with 1,1, 2, etc. He carried the calculation up to the thirteenth place (fourteenth in modern counting), that is 233, though another manuscript carries it to the next place: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377. Fibonacci did not speak about the golden ratio as the limit of the ratio of consecutive numbers in this sequence.

Solution:

This C Program Find the Fibonacci Sequence of a Number in C Program. nth Number is enter through keyboard.

  1. #include <stdio.h>
  2. int fibo(int);
  3. int main()
  4. {
  5.     int num;
  6.     int result;
  7.     printf("Enter the nth number in fibonacci series: ");
  8.     scanf("%d", &num);
  9.     if (num < 0)
  10.     {
  11.         printf("The fibonacci of a negative number is not possible.\n");
  12.     }
  13.     else
  14.     {
  15.         result = fibo(num);
  16.         printf("The %d number in fibonacci series is %d\n", num, result);
  17.     }
  18.     return 0;
  19. }
  20. int fibo(int num)
  21. {
  22.     if (num == 0)
  23.     {
  24.         return 0;
  25.     }
  26.     else if (num == 1)
  27.     {
  28.         return 1;
  29.     }
  30.     else
  31.     {
  32.         return(fibo(num - 1) + fibo(num - 2));
  33.     }
  34.    
  35. }


Learn More :