Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,859 questions

51,780 answers

573 users

How to print the elements of a matrix ordered by rows and by columns in VB.NET

1 Answer

0 votes
Imports System

Public Class PrintMatrixRowsAndColumns_VB
    Public Shared Sub printMatrixRows(ByVal matrix As Integer(,))
        For i As Integer = 0 To matrix.GetLength(0) - 1
            Console.Write("row: {0:D}: ", i)

            For j As Integer = 0 To matrix.GetLength(1) - 1
                Console.Write("{0,4:D} ", matrix(i, j))
            Next

            Console.WriteLine()
        Next
    End Sub

    Public Shared Sub printMatrixColumns(ByVal matrix As Integer(,))
        For j As Integer = 0 To matrix.GetLength(1) - 1
            Console.Write("column {0:D}: ", j)

            For i As Integer = 0 To matrix.GetLength(0) - 1
                Console.Write("{0,4:D} ", matrix(i, j))
            Next

            Console.WriteLine()
        Next
    End Sub

    Public Shared Sub Main(ByVal args As String())
        Dim matrix As Integer(,) = {
        {4, 7, 9, 18, 29, 0},
        {1, 9, 18, 99, 4, 3},
        {9, 17, 89, 2, 7, 5},
        {19, 49, 6, 1, 9, 8},
        {29, 4, 7, 9, 18, 6}}

        printMatrixRows(matrix)

        Console.WriteLine()

        printMatrixColumns(matrix)
    End Sub
End Class



' run:
'
' row: 0:    4    7    9   18   29    0 
' row: 1:    1    9   18   99    4    3 
' row: 2:    9   17   89    2    7    5 
' row: 3:   19   49    6    1    9    8 
' row: 4:   29    4    7    9   18    6 
'
' column 0:    4    1    9   19   29 
' column 1:    7    9   17   49    4 
' column 2:    9   18   89    6    7 
' column 3:   18   99    2    1    9 
' column 4:   29    4    7    9   18 
' column 5:    0    3    5    8    6
'
'

 



answered Jul 12, 2024 by avibootz

Related questions

...