Question: Sort Function ASSIGNMENT: Write a program to sort an array in ascending order. Using a function, ask the user to enter 10 integer values into
Sort Function
ASSIGNMENT:
Write a program to sort an array in ascending order. Using a function, ask the user to enter 10 integer values into an array, in any order. Using a 2nd function, display the un-sorted array values as entered by the user. Using a 3rd function, sort the array values using a bubble sort. Finally, using the 2nd function again, display the sorted array values. Each function will have the entire array and it's size passed to the function.
The algorithm for a simple bubble sort is:
Create an outer loop that runs 1 time less than the number of elements in the array.
This controls the number of passes for the bubble sort.
Create an inner loop that runs 1 time less than the number of elements in the array minus the count of the outer loop.
This controls the number of comparisons for each pass of the bubble sort. Inside the inner loop, compare adjacent elements. If they are out of order, swap the elements. Remember, to swap array elements, a temporary variable is necessary.
Example Run #1: (bold type is what is entered by the user)
Enter a value for array element [0]: 5.6
Enter a value for array element [1]: 9.1
Enter a value for array element [2]: 11.5
Enter a value for array element [3]: 3.1
Enter a value for array element [4]: 0.2
Enter a value for array element [5]: 0.8
Enter a value for array element [6]: 1.4
Enter a value for array element [7]: 6.0
Enter a value for array element [8]: 4.7
Enter a value for array element [9]: 7.4
The un-sorted array:
5.60
9.10
11.50
3.10
0.20
0.80
1.40
6.00
4.70
7.40
The sorted array:
0.20
0.80
1.40
3.10
4.70
5.60
6.00
7.40
9.10
11.50
The example run shows EXACTLY how your program input and output will look.
Write in C, with printf and scanf statement. With constants. No floats please
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
