Professional Documents
Culture Documents
________________________________
Tasks
1. Write a program that does the following:
a. Create a global array to hold 10,000 random numbers between 1 and 1000
b. The array size MUST be represented in all places by a symbolic constant
c. Create functions to sort the array using different algorithms. Pick at least 2:
o Bubble sort
o Insertion sort
o Selection sort
d. Using the clock() function provided in time.h, calculate how many milliseconds it takes to
perform each sort on average.
o The clock() function returns how many clock cycles have executed at a given point
o You’ll need to use the constant CLOCKS_PER_SEC to convert elapsed clock cycles to
milliseconds
e. Call each different sort at least 10 times with different sets of random data to get the
average time for that method
f. The average time should be a floating point number showing 1 decimal place
2. Use the references listed on the next page for help on the clock() function and the different sorting
algorithms
3. You should also include a printArray() function so that you can test your sorting algorithms to
make sure they are working (I suggest using a smaller array size while testing the algorithms)
4. The final screen output should look similar to the examples on the next page.
5. When you are satisfied that the program builds and runs successfully, upload your C file via the
PA9 assignment on Canvas.
Example Output
Let’s see how fast these algorithms can sort 10,000 integers: