DSA 5.73 : Fibonacci using iteration

PHOTO EMBED

Sat Mar 11 2023 15:19:40 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

#include <iostream>
using namespace std;

int fib(int n)
{
    int t0 = 0, t1 = 1, s=0, i;
    if (n<=1)
        return n;
    else
        for(i=2;i<=n;i++)
        {
            s = t0 + t1;
            t0 = t1;
            t1 = s;
        } 
        return s;
}

int main() 
{
    cout << fib(9);
    return 0;
}
content_copyCOPY