UMBC CMSC201, Computer Science I, Spring 1994
Sections 0101, 0102 and Honors
Due: February 24, 1994
Click here for the latest news
The main objective of this assignment is make sure that
everyone has learned enough about C and the UNIX system to
write a simple program with a loop, compile it, run it and turn in
the program using mail.
Write a program which asks the user for an integer input, call it
n, and prints out the n-th Fibonacci number,
F(n). The Fibonacci numbers are defined in the following way:
So, for example, the first ten Fibonacci numbers F(1), ...,
F(10) are: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55.
- F(1) = 1.
- F(2) = 1.
- For i > 2,
F(i) = F(i-1) + F(i-2).
Figure out how you can calculate the Fibonacci numbers on paper first.
Now do this with as few variables as you can. To help debug your program,
you may want to insert (temporarily) some print statements inside your
loop which report the values of your variables. You will have to treat
the first and second Fibonacci numbers as special cases.
Modify your program so that it repeatedly asks the user for input,
until the user enters -1. What happens when the user asks for
the 47th Fibonacci number? Why? Can you fix this problem?
What to turn in:
When you are sure that your program is properly documented and that
it is working correctly for the first twenty Fibonacci numbers,
turn in your program using the mail command. For example, if you named
your file project1.c, then issue the following command:
% mail firstname.lastname@example.org < project1.c
Note that the mail address is email@example.com not
Please do not use any other mail programs (e.g.,
elm, pine, mime, etc.). Mail messages confirming the receipt
of your programs will be sent out periodically, roughly once
This project is due by midnight on Thursday, February 24, 1994.
We will use the system clock on umbc8 as the final arbiter
of time and date. If you turn in your project after the due date,
a 4% penalty will be assessed. The penalty doubles every 24 hour
period, including the weekend. For example, if you turn in the project
on Monday, February 28, a 64% penalty will be assessed.
Last Modified: June 10, 1994
Richard Chang, firstname.lastname@example.org