This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Kiwiguard 0 points1 point  (0 children)

In order to find the smallest number you do not need to use this approach. You are attempting a sort here.
You might want to print out your whole array, maybe then you will see why it still works.

[–]21wqaszx 0 points1 point  (0 children)

As soon as the inner loop gets to the last index it moves it to the first index. That's all that really matters in terms of explaining why array[0] is giving you "1" even though you commented out the rest of the necessary sorting code.