Saturday, August 20, 2011

Find nth term in fibnacci series using Recursion

//Find nth term in fibnacci series using Recursion.
#include<stdio.h>
#include<conio.h>
main()
{
      int n;
      int fib(int prev,int curr,int n);
      printf("Enter the whichth number you want to see in fibnacci series :");
      scanf("%d",&n);
      printf("\n the term is %d",fib(1,1,n));
      getch();
      return 0;
}
int fib(int prev,int curr,int n)
{
    if(n==0)
    return 0;
    if(n==1)
    return prev;
    return fib(curr,prev+curr,n-1);    
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More