COMP 235, Fall 2022, Program 2

Dynamic Memory

Due Monday, September 12 by the start of class.

Start by creating a single C source file. You are going to write a program that lets the user input some integers, then outputs some statistics about them.

Your program needs to:

  1. Prompt the user for a number (the number of integers to input).
  2. Let the user input one integer at a time, until the desired number of integers are received.
  3. Print out all the integers on one line, separated by a comma (no spaces).
  4. Compute and print out the min, max, average, and sum.

You may assume that the user always enters integers correctly (e.g., no floats or weird inputs). You should use dynamic memory to store the input numbers.

It might look something like this:

$ gcc -o nums nums.c
$ ./nums
How many integers? 5
> 1
> 3
> 42
> 7
> -1
You entered: 1,3,42,7,-1
Min: -1
Max: 42
Avg: 10.40
Sum: 52

Submission

You must submit your program file on the department server. As before, use the handin program, this time with assignment “proj2”. For example:

handin comp235 proj2 nums.c

If you did not write the program on the department server, you will first need to transfer the file to the server. I can help with this, although the details depend on your operating system – come to office hours or email me.