SI 204 Spring 2017 / HWs


This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

Homework 24: Sorting

Name: _____________________________________________ Alpha: ___________________

Describe help received: ________________________________________________________

  • Due before class on Wednesday, March 22
  • This homework contains code to be submitted electronically. Put your code in a folder called hw24 and submit using the 204sub command.
  • This is an electronic homework and you do not need to print out anything to turn in during class.

Assignment

  1. Required reading: Sections 1 (Function Design) and 2 (Sorting), but not including section 2.4, from the Unit 7 notes,
  2. Write a program called sort6.c that reads in 6 numbers from the user and prints them out from largest to smallest.

    Of course, you should store them in an array and write a function to sort that array in largest-to-smallest order.

    Example runs:

    roche@ubuntu$ ./sort6
    Enter 6 numbers: 1 2 3 4 5 6
    6
    5
    4
    3
    2
    1
    roche@ubuntu$ ./sort6
    Enter 6 numbers: 32 1 18 3 3 10
    32
    18
    10
    3
    3
    1
    roche@ubuntu$ ./sort6
    Enter 6 numbers: 7 7 8 5 20 6
    20
    8
    7
    7
    6
    5