HOME

Monday, September 7, 2015

FIBONICCI SERIES USING RECURSION IN C++

#include<iostream>
using namespace std;
int fibo(int, int, int);
int main()
{
    int n;
    cout<<"Enter the number"<<endl;
    cin>>n;
    fibo(0,1,n);
return 0;
}
int fibo(int a, int b, int n)
{
    int c;
    if(n==0)
    {
        return 0;
    }
    else{
        cout<<a<<"\t";
        c=a+b;
        a=b;
        b=c;
    return fibo(a,b,(n-1));
    }
}

No comments:

Post a Comment