CSC 270
Homework 6

Assigned Nov. 6, due Nov. 13

In this assignment, you'll basically re-do homework 2 and homework 3 in C. Most of the code you wrote for those assignments should still work; it'll need only minor modifications to become legal, working C code.

Write a C program that reads in an int, then that many double numbers into an array, prints their sum and average (appropriately labelled), and prints out how many of them are positive. It will then sort the array (using bubble-sort or some other sorting algorithm of your choice) and print out the sorted array.

Each of the following tasks should be done by a function to which the array (and its size) is passed:

The int at the beginning should be no smaller than 0, nor larger than 100; if it is, your program should print an appropriate error message rather than asking for the doubles and printing the results.

For example, if the input were
5 3.7 5.2 -4.7 -62 14.7
the output might be
Sum: -43.1
Average: -8.62
3 of your 5 numbers are positive.
After sorting, the numbers are...
-62 -4.7 3.7 5 5.2 14.7

Also turn in sample runs with well-chosen test cases.

Points to remember:


Last modified: Sat Nov 4 14:46:25 EST 2000
Stephen Bloch / sbloch@adelphi.edu