Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Arrays.

EDITTask 9 of 28 · step 5: SortingSort a copy
Sort a copy in practice/01/

The function sort_array (selection sort), a copy sorted, printing it and the median.

Checklist

  • Every task is one commit with a clear message.
  • Zero compiler warnings: the code builds with -Werror.
  • Once per topic you step through your code in the debugger (CLion, gdb).
  • Every function has preconditions and postconditions, and assert tests check them.
Details & hint
  • The outer loop i from 0 to n - 2, the inner j looks for the smallest of the rest.
  • A swap through temp.
  • main: a copy with a loop, sort_array(sorted, DAYS), the median sorted[DAYS / 2].

Stuck? Sort the copy, not temperatures: the search has to return the day in the original order.

practice 01 main.c Code Diff
UNCHANGED This step does not change this file.
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
printf("\n");
printf("Algorithm: the average of grades\n");
printf("1. Add up all the grades.\n");
printf("2. Count how many grades there are.\n");
printf("3. Divide the sum by the count.\n");
printf("4. Print the answer.\n");
printf("\n");
printf("Grade\tMeaning\n");
printf("10\t\"excellent\"\n");
printf("5\t\"satisfactory\"\n");
printf("File: C:\\course\\practice\\01\\main.c\n");
printf("Done: 100%%\n");
return 0;
}