5.21 · exercise

min-max tournament

Eight entries, one pass, two records: find the smallest and the largest element of the array, and print both.

Seed both records with element zero (the starter already has), then walk the rest once. Each element gets two comparisons: does it beat the minimum, does it beat the maximum. Resist the urge to loop twice.

what is checked

  • min and max each printed on their own line
  • the program exits cleanly
  • comparisons decide the records

Specification

args
stdoutprints the expected output
exitexits with the expected code
sourceuses cmp

Checked by running your program against expected behavior, never by matching a stored solution.

loading editor...
Open in playground