Initial end term of the Fibonacci sequence (closed interval)

Asked

Viewed 284 times

0

I have to make a list of exercises in C and Java, but I could not understand the logic in this exercise. Could someone help?

Ask the user for the initial and final Fibonacci sequence term (closed interval) and print the result.

Ex: Sequence of Finomacci 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Initial term 4

Final term 8

  • 5

    This question seems to be decontextualized because it asks you to solve the entire exercise without demonstrating your attempts, without showing your own code and without saying what you don’t understand about the programming problem itself.

1 answer

1

The Fibonacci sequence and defined as follows:

F(1) = 0
F(2) = 1
F(n) = F(n-1) + F(n-2), se n > 2

That is, the sequence begins with the terms 0 and 1 and from there the next terms are the sum of the previous two. For example:

F(4) = F(3) + F(2) = 1 + 1 = 2

Your exercise asks the user between two parameters, inicio and fim. What Voce has to print are the numbers F(n) for n between the numbers inicio and fim. For example, if inicio = 4 and fim = 8, as in your example, Voce has to print F(4), F(5), F(6), F(7), F(8).

  • I know how to do the sequence. I’ve done other exercises, but I don’t understand how to do this one. Because it will print from the 4th term and end in the 8th term following the example. It will not show the 0, 1, 1 .

  • If Voce knows how to generate the sequence, and only put the imprint inside a if. If the term value is within the range print it, otherwise :)

  • When I get back from college I try again. I have 3 lists to do of C and Java. I’m glad that C is finished kk , but thanks a lot ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.