Bubble Sort with Swap Count
PROSorting & SearchingBubble Sort
1D & 2D Arrays
Write a program that inputs 5 integers into an array and sorts them into **ascending** order using a bubble sort. Swap two neighbouring values only when the left one is **strictly greater** than the right one.
Output the 5 sorted values, one per line, followed by a final line showing the total number of swaps made during the sort.
For example, the input 5 1 4 2 8 outputs 1, 2, 4, 5, 8 (one per line) and then 4.
Example Input
5
1
4
2
8
Example Output
1
2
4
5
8
4
0% (0 passed / 0 attempted)