Fibonacci

The Fibonacci series is a series of numbers in which the first two numbers are 0 and 1. Each subsequent number is the sum of the previous two. So, the third Fibonacci number is (0 + 1) = 1. The next is (1 + 1) = 2. Then (1 + 2) = 3. Then (2 + 3) = 5. Then (3 + 5) = 8. And so on. The Fibonacci series has many interesting mathematical properties and shows up in surprising places in nature.

  • Write a program that uses a for loop to print the first 20 Fibonacci numbers.

  • Remember that the first two (known as f0 and f1) are predefined as 0 and 1. All subsequent numbers are calculated from there.

  • Modify your solution (if necessary) so that the sequence number is printed out next to the fibonacci value. Make sure that sequence numbers 0 and 1 match up with the first two predefined values:

    0: 0
    1: 1
    2: 1
    3: 2
    4: 3
    5: 5
    6: 8
    7: 13
    ...
    


Up