Program in VB.net to find the even elements of a 2D array

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 169
Suppose we have a 2D array

{
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
}

We need to find the even elements of the 2D array. The below program will do so

Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication2
Class Program
Private Shared Sub Main(args As String())


Dim row As Integer = 4
Dim col As Integer = 4
Dim matrix As Integer(,) = New Integer(3, 3) {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}
For i As Integer = 0 To row - 1
For j As Integer = 0 To col - 1
If matrix(i, j) Mod 2 = 0 Then
Console.Write(matrix(i, j) & " ")
End If

Next
Next
Console.ReadKey()

End Sub
End Class
End Namespace

Result
--------
2 4 6 8 10 12 14 16

Comments or Responses

Login to post response