
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

CS 140 Fall 2008
The purpose of this assignment is to give you some experience working with the functions printf() and scanf(), variables of type int, arithmetic operators, and for loops.
For this assignment, you will develop a program that will print the Fibonacci Sequence of a user-specified length. The Fibonacci Sequence starts with the integers 1 and 1, and each subsequent integer in the sequence is the sum of the previous two. For example, the first six (6) numbers in the sequence are:
1, 1, 2, 3, 5, 8
Here, 1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, and 3 + 5 = 8.
Your program will prompt the user for the length of the sequence, and then print a sequence of that length. An example run of your program might look like:
$./a.out Enter the length of the sequence: 6 The sequence is: 1, 1, 2, 3, 5, 8 $
The program should be saved in a file named fibonacci.c.
Your program should include variables of type int to hold the previous two values in the sequence, the current value in the sequence, the user-specified length, and a loop-control variable. Recall our discussion of previous assignments when writing this program – use meaningful variable names, proper formatting, blank lines, etc. Be sure to model the output of your program after the example given above. As always, be sure to compile your program using gcc -O -Wall
The assignment is due at the start of class on October 3rd, 2008. Leave your source code in your cs140/assignment4 directory. Do not modify your program after the due date.
You are required to work individually on this assignment. Please do not consult anyone other than me on any aspect of this assignment.