~riderius/cpp-code

cpp-code/fibonacci.cpp -rw-r--r-- 343 bytes
380d65aariderius digits_analysis.cpp: argv[1] can replace n 11 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

int fib(int n);

int main(void)
{
    using namespace std;

    int n;
    cin >> n;
    cout << fib(n);

    return 0;
}

int fib(int n)
{
    int fib0 = 0, fib1 = 1, temp, count = 1;
    while (count != n) {
        temp = fib1;
        fib1 = fib0 + fib1;
        fib0 = temp;
        count++;
    }
    return fib1;
}