Share
Fibonacci – recursive algorithm

Fibonacci – recursive algorithm

Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:

1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , …

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

0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , …
#include <stdio.h>

long fibo(long x)
{
	if (x == 0 || x == 1)
	 return 1;
	 else
	 return fibo(x-1)+fibo(x-2);
 }

 void main()
 {
	 int n;
	 printf("n=");scanf("%d",&n);
	 printf("fibo(%d) = %ld\n",n,fibo(n));
 }

104,307 total views, 341 views today