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

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:

  1. 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.
  2. The main loop of the program is implemented using while. However, it is a counter-controlled loop, so it can also be implemented as a for loop. Re-write the main loop as a for loop.
  3. 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.