0

I am pretty confused about the concept of the Fibonacci series. I am trying to make a C++ program of Fibonacci series which asks the user to input 2 different numbers and number of iterations like input one = 9 and input two = 10, the number of interactions = 4, and the Fibonacci series should go on like 9, 10, 19, 29... I am trying to make it through for loop but I am pretty confused about what should I put into the for loop.

for (int i,j; i<it, j < it; ++i, ++j) 
    next = i+j;
    i = j;
    j = next;

I have done it like this where i = input one, j = input two, and it = number of iterations.

Loppy2323
  • 82
  • 6
  • 1
    You need a loop that iterates `it` times. What you wrote does not do that. – dxiv Jun 18 '20 at 02:29
  • okay, so how should I do it? – Loppy2323 Jun 18 '20 at 02:31
  • 1
    Writing a fixed length loop is the [first example](https://en.cppreference.com/w/cpp/language/for) in any textbook. – dxiv Jun 18 '20 at 02:34
  • where you talking something like this: /* for (int i,j; i 1){ next = i+j; i = j; j = next; cout << inc < – Loppy2323 Jun 18 '20 at 02:49
  • 1
    No, that's not a fixed length loop, besides, it makes no sense to compare `i, j` against `it`. I was talking about the plain classic `for(int n = 0; n < it; n++)` loop. Just put the Fibonacci calculation inside, and once it's done you'll have the result of `it` iterations. – dxiv Jun 18 '20 at 02:59
  • 1
    Instead of thinking in terms of code, think in terms of the algorithm. If you were telling a person how to accomplish this task, what would you tell them? – JaMiT Jun 18 '20 at 04:17

0 Answers0