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
from System import *
from System.Collections.Generic import *
from System.Linq import *
class Program(object):
def Main(args):
row = 4
col = 4
matrix = Array[int]((, , , ))
i = 0
while i < row:
j = 0
while j < col:
if matrix[i][j] % 2 == 0:
Console.Write(matrix[i][j] + " ")
j += 1
i += 1
Console.ReadKey()
Main = staticmethod(Main)
Result
--------
2 4 6 8 10 12 14 16