View Single Post
  #1  
Old 06-12-2009, 06:08 PM
shmsa's Avatar
shmsa shmsa is offline
Grown up punk

 
Join Date: Oct 2007
Location: Muslim Town Multan
Posts: 195
Contact Number: 0322-6196713
Program / Discipline: BSIT
Class Roll Number: 07-22
shmsa is a jewel in the roughshmsa is a jewel in the roughshmsa is a jewel in the roughshmsa is a jewel in the rough
lectures Q3:Jagged Array of 3 rows

create a jagged array of three rows, create different length of rows and show the sum of elements of each row.
Code:
Module jaggedArray

    Sub Main()
        Dim ar1 As Integer()()
        ar1 = New Integer(2)() {}
        ar1(0) = New Integer(2) {1, 2, 3}
        ar1(1) = New Integer(1) {4, 5}
        ar1(2) = New Integer(0) {6}

        Dim i, j, sum As Integer
        For i = 0 To ar1.GetUpperBound(0)
            For j = 0 To ar1(i).GetUpperBound(0)
                Console.Write(ar1(i)(j) & vbTab)
            Next
            Console.Write(vbCrLf)
        Next

        For i = 0 To 2
            sum = 0
            For j = 0 To ar1(i).GetUpperBound(0)
                sum = ar1(i)(j) + sum
            Next

            Console.Write(sum & vbCrLf)
        Next
    End Sub

End Module

Reply With Quote