Program for fibonacci numbers

By
Advertisement
In mathematics, the Fibonacci numbers, commonly denoted Fn form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,

 

and

 

for n > 1.

The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

//Fibonacci Series using Recursion 

int fib(int n) 
{ 
if (n <= 1) 
 return n; 
return fib(n-1) + fib(n-2); 
} 

int main () 
{ 
int n = 9; 
printf("%d", fib(n)); 
getchar(); 
return 0; 
} 

0 comments:

Post a Comment