Fibonacci Program Recursive Function in C Language

Fibonacci Series C Program with Recursive Function


Febonacci Series is calculated using Fn=F(n-1)+F(n-2) method. The the Series will be like below:
Sample Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
Here we are generating the Fibonacci Series using recursive function. The function fib will do the recursive operation.


int fib(int n);
void main() {
int a=5;
int i=0;
for(i=0;i<10;i++){
printf("%d ", fib(i));
}
}
int fib(int n)
{
if (n < 2)
return n;
else
return fib(n-1) + fib(n-2);
}

Output of the above program / Code will be
0 1 1 2 3 5 8 13 21 34


Related Topic Java Program / Code for Fibonacci
Fibonacci Program in C Language
C Program to calculate Sum of Series
Reverse Array C Program Language
8 Queens Problem with Recursive Function in CPP

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback