CMSC 104, Spring 2014
Homework 3
Out: Wednesday 3/26/14
Due: Before 11:59 PM on Tuesday,
4/1/14
Note that late homeworks will NOT be accepted.
The Objectives
- To practice using C loop structures.
- To practice modifying and enhancing an existing program.
The Assignment
The purpose of this homework is to give you practice using C loop structures (while and for). The three exercises require you to modify the program hw3.c, a simple program that computes the mean, variance, and standard deviation of a list of numbers entered by the user.
Each exercise is described in a comment block within the program, but we summarize them below:
-
The program prompts the user to enter the number of data items (n) that
they want to enter, but it does not check that the number is non-negative.
Write a
while
loop that prompts the user to re-enter n until they have provided a non-negative value. -
The main loop of the program is implemented using
while
. However, it is a counter-controlled loop, so it can also be implemented as afor
loop. Re-write the main loop as afor
loop. - Modify the program so that it computes and prints the maximum and minimum data values in addition to the mean, variance, and standard deviation.
Submit your work
Be sure that your completed program is called hw3.c
and is in
your hw3
directory. The next step is to submit your work.
- Change to the
hw3
directory (usepwd
to check that you have done this correctly) and then submit the files to the projecthw3
using the command:linux1[6]% submit cmsc104_cmarron hw3 hw3.c linux1[7]%
- You can use the
submitls
command to check that you have submitted both files:linux1[8]% submitls cmsc104_cmarron hw3 total 5 drwxr-xr-x 2 cmarron rpc 2048 Mar 25 14:05 . drwxr-xr-x 43 cmarron rpc 2048 Mar 25 14:05 .. -rw-r--r-- 1 cmarron rpc 1858 Mar 25 14:05 hw3.c