VB.net Program to Print the Sum of Left Diagonal Elements of Matrix

You are currently viewing VB.net Program to Print the Sum of Left Diagonal Elements of Matrix

VB.Net program to print the sum of left diagonal elements of Matrix

'VB.Net program to print the sum of left diagonal elements of MATRIX.

Module Module1

    Sub Main()
        Dim arr(,) As Integer = New Integer(3, 3) {}
        Dim sum As Integer = 0

        Console.WriteLine("Enter Matrix elements: ")
        For i = 0 To 2 Step 1
            For j = 0 To 2 Step 1
                Console.Write("Enter element[{0}][{1}]: ", i, j)
                arr(i, j) = Integer.Parse(Console.ReadLine())
            Next
        Next

        Console.WriteLine("Matrix: ")
        For i = 0 To 2 Step 1
            For j = 0 To 2 Step 1
                Console.Write("{0} ", arr(i, j))
                If (i = j) Then
                    sum = sum + arr(i, j)
                End If
            Next
            Console.WriteLine()
        Next

        Console.WriteLine("Sum of left diagonal elements is: {0}", sum)
    End Sub
    
End Module
Enter Matrix elements:
Enter element[0][0]: 10
Enter element[0][1]: 20
Enter element[0][2]: 30
Enter element[1][0]: 40
Enter element[1][1]: 50
Enter element[1][2]: 60
Enter element[2][0]: 70
Enter element[2][1]: 80
Enter element[2][2]: 90
Matrix:
10 20 30
40 50 60
70 80 90
Sum of left diagonal elements is: 150
Press any key to continue . . .

Ranjith Kumar

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

Leave a Reply