Winter 2005 UCLA CS 31 Section 1 (Shinnerl)

Written HW 1 FAQ File

The most recently added question is shown last.
Questions are in boldface. Answers are in regular text.

Last Update: 5:25pm Fri., 2/11.

  1. The following is an alternative restatement of Problem 7 (Fibonacci numbers).
    Fibonacci numbers. The Fibonacci Sequence is 1,1,2,3,5,8,13,21,.... It can be defined by the following three rules.
      
          F(1) = 1.
          F(2) = 1.
          F(i) = F(i-1) + F(i-2)  for every integer i > 2.
    
    Implement a C++ function that computes the ith Fibonacci number F(i), for any user-specified i >= 1. Make sure that your solution uses a constant amount of storage and a total number of arithmetic operations proportional to input i.
    This restatement starts the indexing at 1 instead of 0, to simplify the language. You may use either form of the definition (start at 0, or start at 1).


Written HW 1 home page