How to do this complicated question?

In the 13th century, the Italian mathematician Leonardo Fibonacci—as a way to explain the geometric growth of a population of rabbits—devised a mathematical sequence that now bears his name. The first two terms in this sequence, Fib(0) and Fib(1), are 0 and 1, and every subsequent term is the sum of the preceding two. Thus, the first several terms in the Fibonacci sequence look like this:

Fib(0) = 0
Fib(1) = 1
Fib(2) = 1 (0 + 1)
Fib(3) = 2 (1 + 1)
Fib(4) = 3 (1 + 2)
Fib(5) = 5 (2 + 3)

Write a program that displays the terms in the Fibonacci sequence, starting with Fib(0) and continuing as long as the terms are less than 1,000.
Hi, I'm sorry but no one is going to answer this nor the other 3 homework questions that you have posted. We're here to help but only after you've made a real attempt at solving these questions.
Last edited on
closed account (o3hC5Di1)
Hi there,

Please post some more specifics on what it is that you struggle with about this question, or post your code so far and tell us where you are stuck.

A hint to get you started:
Use separate variables to keep the previous two numbers which you update with every loop iteration.

To clarify Mr, Soranz comment:

Forum Rules wrote:
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.


All the best,
NwN
Topic archived. No new replies allowed.