You are sorting the movieratings
array in ascending order and printing ctr
elements from the beginning so it prints the movies with lowest rating.
sort the array in descending order i.e change this if (movieratings[i] > movieratings[i+1])
to if (movieratings[i] < movieratings[i+1])
0
solved What is wrong with my bubble sort? [closed]