Cyran Meriel wrote:

But like I said if theres more numbers that are lesser than the first number how do the program sort between those numbers?.. 20 is larger than 10, 17, and 5. so 10,17 and 5 gets num[0] but then what? its not in the right order and I cant see where in the program it sorts between those numbers.

In a bubble sort, only one number is guaranteed to be in place with each pass of the inner loop. So, with this example...

20 is larger than 10. So, 10 gets moved to the zeroth position. And 20 gets moved to where the 10 was located. The two numbers are swapped.

10 is not larger than 17. So, nothing happens... notice that I said 10, and not 20, as that is the new number in the zeroth position.

10 is larger than 5. So, 5 gets moved to the zeroth position. And 10 gets moved to where the 5 was located. The two numbers are swapped.

This completes the inner loop. And one iteration of the outer loop. The result is that the smallest number is at the zeroth position. The next iteration of the outer loop runs, with the "i" variable on the first position (and of course, all comparison and swapping will be with the first position).

Henry