Recursion/Programs/fibonacci.cpp
//iterative function to find fibonacci of a given number
iterative function to find fibonacci of a given number
iterative function to find fibonacci of a given number
int fib(int n)
{
    int t0 = 0, t1 =1,s=0;
    cout<<t0<<" "<<t1<<" ";
    if(n<=1)
    {
        return n;
    }
    for(int i=2;i<=n;i++)
    {
        s=t0+t1;
        t0=t1;
        t1=s;
        cout<<s<<" ";
    }
    return s;
}
int fib ( int n ) { int t0 = 0 , t1 = 1 , s = 0 ; cout << t0 << " " << t1 << " " ; if ( n <= 1 ) { return n ; } for ( int i = 2 ; i <= n ; i ++ ) { s = t0 + t1 ; t0 = t1 ; t1 = s ; cout << s << " " ; } return s ; }
iterative function to find fibonacci of a given number
iterative function to find fibonacci of a given number
/* int t0 = 0, t1 =1,s=0; */ /* cout<<t0<<" "<<t1<<" "; */