calculating a fibonacci sequence

fgfdfhfdh
Last edited on
The counter should not be used in generation of the fibonnaci numbers. You need the 2 previous numbers add them and you get the next number.
Something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
int first = 1;
int second = 1;
int next = 1;
cout << "0 1 1";
int counter =3; // already printed 0, 1 and 1
while(counter <= num){
    int aux = next;
    next = first + second;
    first = second;
    second = aux;
    ++counter;
    cout << next << " ";
}


If I'm not mistaking you have to display that many fibonnaci numbers not to display the last one.
Last edited on
Topic archived. No new replies allowed.