pete > courses > CS 202 Fall 26 > Tier 2, Phase 3, Problem 01: simple stats
Tier 2, Phase 3, Problem 01: simple stats
The purpose of this is assignment is to get you started programming in C. As such, it is not algorithmically complex: most of the effort will be in developing a workflow (edit, compile, run) and figuring out how to say what you want to say using C rather than, eg, Python or Java. To that end, a really effective approach might be to devise a rough solution in a language you’re more comfortable with and then translate it to C using the course notes as reference.
Your program will accept a list of numbers typed at the keyboard. When the user is done entering numbers, they will press Control-D to indicate end of file. After that, your program will print out the minimum, maximum, and average of the numbers entered. Your program must produce no output other than the min/max/average lines at the end.
Here is a couple example runs:
$ ./numbers 123456789 987654321 112233 445566 123 321 Min: 123 Max: 987654321 Avg: 185278225
$ ./numbers -123 -54321 12355 984471 57295 4482911 Min: -54321 Max: 4482911 Avg: 913764
In both cases, the first six lines were typed by the user, after which the user pressed Control-D. The final three lines were printed by the program, after which the program exited. In these examples, the average is rounded down, as happens with integer division: this is acceptable.
Your program must both compile and run on weathertop. You may edit your code on your own computer and scp it to weathertop, as you have done with assignment submissions, whenever you want to compile and run it. You may find this tedious, however, if you save and re-compile often (which is a good idea!). To make that easier, remote editing features of text editors are discussed at the bottom of the guide to using department machines.
Extra information
If you #include <limits.h>, you will have a few constants available to you:
- INT_MAX is the maximum value that can be stored in a variable of type int
- INT_MIN is the minimum value that can be stored in a variable of type int
Assumptions
You may assume that the user will never enter a value greater than INT_MAX or less than INT_MIN.
You may assume that the sum of all values entered will never be greated than INT_MAX or less than INT_MIN.
You may assume that the user will never enter a quantity of number greater than INT_MAX.
You may assume that the user will always enter valid numerical data.
You may assume that the user will always enter at least one number.
Restrictions
You are limited to the following library functions:
- fgets
- atoi
- printf
You may write as many of your own functions as you like, however.
Submission Instructions
Copy the numbers.c file to weathertop and then run:
$ 202 submit t2p3p01 numbers.c
Submissions will not be accepted after 2pm on DDDDDDD, DD MMM YY.