First, Middle, Last
This is a warmup exercise.
It is not compulsory, and may be
completed individually or with your lab partner.
Download
firstMiddleLast.c
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week05/files/firstMiddleLast.c .
The file firstMiddleLast.c
contains a main function
which reads values into an array. You are to implement
the void printFirstMiddleLast(int size, int array[MAX_LENGTH])
function which should print the first, middle, and last
elements of the array, each on a new line.
The middle element of the array is the one with index
size/2
.
Some Examples
Enter array size: 5 Enter array values: 1 2 3 4 5 1 3 5
Enter array size: 6 Enter array values: 1 2 3 4 5 6 1 4 6
To run some simple automated tests:
$ 1511 autotest firstMiddleLast
To run Styl-o-matic:
$ 1511 stylomatic firstMiddleLast.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk05_firstMiddleLast
Or, if you are working from home, upload the relevant file(s) to the wk05_firstMiddleLast activity on Give Online.