E-Pen InMotion E-Pen Instrukcja Użytkownika Strona 13

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 15
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 12
Fibonacci Numbers
1. Leonardo Fibonacci (aka Leonardo Pisano Bigollo, Leonardo of Pisa, Leonardo Pisano, Leonardo Bonacci) was a 13th century
Italian mathematician (and not a pizza maker from New Jersey, as many claim). He invented a sequence of numbers in which you
start with 1, 1 and get each additional number by adding together the previous two numbers. Thus, the sequence is:
1, 1, 2, 3, 5, 8, 13, 21, 34, ...
because 1+1=2, 1+2=3, 2+3=5, 5+8=13, 8+13=21, 13+21=34, and so on.
2. Write a program to calculate and display the first 10 Fibonacci numbers.
Hint:
Some terminology: A string is a sequence of characters. Variables can have string values, like “abc”, or numeric values, like 27.
You can build a string using the join block in Operators. For example, if you have variables FirstName and LastName, you could
join these together and store them in a variable called FullName with the following blocks:
One problem is that this doesn’t insert a space between the first and last names. You need to add the space yourself. For example,
the following block joins FirstName to the join of a space (in the white square) and LastName:
You can also join a string variable to itself. This is a good way to keep adding stuff to the end of a string (like each Fibonacci
number that you calculate, HINT, HINT). For example, the following initializes FullName to nothing, then adds FirstName, then
adds a space, then adds LastName:
3. Modify your project so the cat asks how many Fibonacci numbers you want to generate, then generate that many and display
them.
4. Name your project Fibonacci and save it.
Przeglądanie stron 12
1 2 ... 8 9 10 11 12 13 14 15

Komentarze do niniejszej Instrukcji

Brak uwag