Docsity

CS 140 Assignment 4: Generating a User-Specified Length Fibonacci Sequence - Prof. Andrew , Assignments of Computer Science

Toggle sidebar
bg1
CS 140 Fall 2008
Assignment #4:
The Fibonacci Sequence
Dr. Andrew R. Dalton
September 26th, 2008
1 Overview
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.
2 Details
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 <filename>and correct all warnings (and errors) before handing in the
source code.
3 Hand-In Instructions
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.
4 Notes on Collaboration
You are required to work individually on this assignment. Please do not consult anyone other than me
on any aspect of this assignment.
1

Partial preview of the text

Download CS 140 Assignment 4: Generating a User-Specified Length Fibonacci Sequence - Prof. Andrew and more Assignments Computer Science in PDF only on Docsity!

CS 140 Fall 2008

Assignment #4:

The Fibonacci Sequence

Dr. Andrew R. Dalton

September 26th, 2008

1 Overview

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.

2 Details

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 and correct all warnings (and errors) before handing in the source code.

3 Hand-In Instructions

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.

4 Notes on Collaboration

You are required to work individually on this assignment. Please do not consult anyone other than me on any aspect of this assignment.