Swapping number algorithm in c