Swift Program to Create a Two-Dimensional Array Using the Append() Function

You are currently viewing Swift Program to Create a Two-Dimensional Array Using the Append() Function

Swift program to create a two-dimensional array using the append() function

// Swift program to create a two-dimensional array 
// using append() function

import Swift

var twoDArr=[[Int]]()
var row1 = [Int]()

row1.append(1)
row1.append(3)
row1.append(5)

twoDArr.append(row1)

var row2 = [Int]()

row2.append(2)
row2.append(4)
row2.append(6)

twoDArr.append(row2)

print("Two Dimensional array: ",twoDArr)

Output

Two Dimensional array:  [[1, 3, 5], [2, 4, 6]]

...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