Swift Program to Swap Array Elements Using Swapat() Function

You are currently viewing Swift Program to Swap Array Elements Using Swapat() Function

Swift program to swap array elements using swapAt() function

// Swift program to swap array elements using
// swapAt() function

import Swift

var arr:[Int] = [12,10,25,20,50]

print("Array before swapping: ",arr)

arr.swapAt(2,4)

print("Array after swapping: ",arr)

output

Array before swapping:  [12, 10, 25, 20, 50]
Array after swapping:  [12, 10, 50, 20, 25]

...Program finished with exit code 0
Press ENTER to exit console.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply