Fibonacci Number program in C++ using Recursion

0
572
dynamic Array in C++
A brief Introduction to java classes

This program shows A Fibonacci Sequence starting from a user’s entered number, the approach used here is recursive.Have a look at the code:

    //febonacci using recursion
    #include<iostream>
    using namespace std;

    int F(int n)
    {
        if(n==0)
            return 0;
        else if(n==1)
            return 1;
        else
            return ((F(n-1)+F(n-2)));

    }
    int main()
    {
        int num;

        cout<<"Enter a number : ";
        cin>>num;

        cout<<F(num)<<endl;

    }

A recursive function is created which takes the user’s entered number as an argument and uses it for finding the next values.

dynamic Array in C++
A brief Introduction to java classes

Leave a Reply