Swift Program to Create a Two-Dimensional Array

You are currently viewing Swift Program to Create a Two-Dimensional Array

Swift program to create a two-dimensional array

// Swift program to create a two-dimensional array

import Swift

let twoArr: [[Int]] = [[1,3,5,7], [2,4,6,8]]

// print first row
print("First Row:")
print(twoArr[0][0])
print(twoArr[0][1])
print(twoArr[0][2])
print(twoArr[0][3])

// print second row
print("Second Row:")
print(twoArr[1][0])
print(twoArr[1][1])
print(twoArr[1][2])
print(twoArr[1][3])

Output

First Row:
1
3
5
7
Second Row:
2
4
6
8

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