Fibonacci



In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence:


Often, especially in modern usage, the sequence is extended by one more initial term:


By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation.

Fibonacci algorithm example in C programming :




#include <stdio.h>

void main()

{

  int a, b, c, i, n;

  a = 0;
  b = 1;

  printf("Enter a number to define the length of fibonacci series: ");
  scanf("%d", &n);
  printf("\nThe Series is: \n");
  printf("%d\t%d", a, b);

  for (i = 0; i < n; i++)

  {

    c = a + b;

    a = b;

    b = c;

    printf("\t%d", c);

  }

  getch();

}


OUTPUT
Enter a number to define the length of fibonacci series: 5
The Series is: 
0 1 1 2 3 5 8

Post a Comment

0 Comments