CS 1713 Introduction to Computer Science -- Spring 2001
Practice Problem on Array of a primitive type

The Fibonacci Sequence consists of the numbers:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, ...
After you start with 0 and 1, each later number is just the sum of the two previous numbers.

Write a program that will calculate and print the first 40 Fibonacci numbers in the following way:

  1. Create an array named fib of 40 ints.
  2. Store 0 and 1 into fib[0] and fib[1] just with simple assignment statements.
  3. Use a loop to store the remaining numbers in locations f[2], f[3], ..., f[39]
  4. Print these numbers.