## PIC 10B

(Sec. 1a-1b)

C++ Programming and Problem Solving

## Instructor: Ivo Dinov, Asst. Prof.Neurology, Mathematics, Statistics

 http://www.math.ucla.edu/~dinov/10b.1.011/

Due Date:

# Wednesday, 8:00 PM, July 18, 2001

Please, submit your homework electronically using the "submit" system. Please try to follow the "good programming" conventions we discussed in class. Write modular code and include all of your functions in the same CPP file as your main.

• (HW_3_1.cpp/exe) Write a program which prompts the user to enter a non-negative integer n, calls a recursive subroutine and reports back the first n Fibonacci numbers. [The Fibonacci numbers are {0, 1, 1, 2, 3, 5, 8, ...} and are obtained by the recursive relationship (from the previous two numbers in the infinite series) Fib(0)=0; Fib(1)=1; for n>1, Fib( n ) = Fib( n - 1 ) + Fib( n – 2 ).] Read this to find out how and why are Fibonacci numbers so important and natural (e.g., golden ratio, music, etc.)

Sample Run:
%> This program computes and reports the first N Fibonacci numbers. Please enter a non-negative integer N, or (Q/X) to exit:
%> -15.2
%> Please enter a non-negative integer N, or (Q/X) to exit:
%> 8
%> The first 8 Fibonacci numbers are {0, 1, 1, 2, 3, 5, 8, 13}!
%> Would you like to see all Fibonacci numbers for another N (Y/N)?
%> N
%> Very well. Bye!

\Ivo D. Dinov, Ph.D., Department of Neurology and Program in Computing, UCLA School of Medicine/