Pages

Tuesday, 16 June 2015

Compute fibonacci term using recursion

Compute fibonacci term using recursion

Coding:

#include<stdio.h>
int fibo_term(int n)
{
if(n==1||n==2)
return n-1;
else
return fibo_term(n-1)+fibo_term(n-2);
}
int main()
{
int b;
printf("Please enter the fibonacci term no(greter than 0):");
scanf("%d",&b);
if(b>0)
printf("Term value is=%d",fibo_term(b));
return 0;
}

Output:
Please enter the fibonacci term no(greter than 0):5
Term value is=3