    01: #include <iostream>
    02:
    03: using namespace std;
    04:
    05: /**
    06:    Computes a Fibonacci number.
    07:    @param n an integer
    08:    @return the nth Fibonacci number
    09: */
    10: int fib(int n)
    11: {
    12:    if (n <= 2) return 1;
    13:    int fold = 1;
    14:    int fold2 = 1;
    15:    int fnew;
    16:    for (int i = 3; i <= n; i++)
    17:    {
    18:       fnew = fold + fold2;
    19:       fold2 = fold;
    20:       fold = fnew;
    21:    }
    22:    return fnew;
    23: }
    24:
    25: int main()
    26: {
    27:    cout << "Enter n: ";
    28:    int n;
    29:    cin >> n;
    30:    int f = fib(n);
    31:    cout << "fib(" << n << ") = " << f << endl;
    32:    return 0;
    33: }