the question given by my teacher is
Write a program that uses an array called marks of length 30. Initialize its values to random numbers between 50 and 100.
-Find the mean for the marks generated
- Print the content of the array.
- Sort the array using Bubble Sort or Selection Sort
- Find the Median value for the marks
- Find the mode of the marks generated.
- Print the array one more time
This is the start i have but i dont know how to do the median and mode with a bubble sort
i dont know how to do the median and mode with a bubble sort
You don't have to do them at the same time. Sort and then think about how you'd find median / mode.
Bubble Sort algorithm? The last part of wikipedia's "optimizing bubble sort" section:
wiki wrote:
To accomplish this in pseudocode we write the following:
1 2 3 4 5 6 7 8 9 10 11 12 13
procedure bubbleSort( A : list of sortable items )
n = length(A)
repeat
newn = 0
for i = 1 to n-1 inclusive doif A[i-1] > A[i] then
swap(A[i-1], A[i])
newn = i
end if
end for
n = newn
until n = 0
end procedure