Monday, November 26, 2012

'C++' PROGRAM TO FIND Nth FIBONACCI NUMBER USING RECURSIVE FUNCTIONS

/* A 'C++' PROGRAM TO FIND Nth FIBONACCI NUMBER USING RECURSIVE FUNCTIONS*/
#include<iostream.h>
#include<conio.h>
int c;
int fibo(int n,int a,int b)
{
    if(n-2!=0)
    {
        c=a+b;
        fibo(--n,b,c);
        return c;
    }
}
void main()
{
    clrscr();
    cout<<"Enter n value:";
    int n;
    cin>>n;
    if(n==1)
        cout<<"\nThe First fibonacci number is :0";
    else if(n==2)
        cout<<"\nThe second fibonacci number is :1";
    else
        cout<<"\nThe fibonacci number "<<n<<" is :"<<fibo(n,0,1);
    getch();
}

/*     OUTPUT
    ------
Enter n value:10

The fibonacci number 10 is :34

*/




1 comment:

  1. this is good post.
    and you can go here

    http://bantalsilikon01.blogspot.com
    http://kursusinternetmarketingmurah.blogspot.com
    http://bumbupecelbali.blogspot.com


    tanks very much.... :)

    ReplyDelete