Вы находитесь на странице: 1из 2

Activity 2#:

class Program
{
static void Main(string[] args)
{
int[,,] anArray = new int[2, 2, 2];

for (int table=0; table< anArray.GetLength(0);table++)


{
for (int row=0; row< anArray.GetLength(1); row++)
{
for (int col = 0; col < anArray.GetLength(2); col++)
{
Console.WriteLine("Enter an element for the array(table{0},
row{1}, col{2}): ", table, row, col);
anArray[table, row, col] = int.Parse(Console.ReadLine());
}
}
}
Console.WriteLine("/n");

foreach (int array in anArray)


{
Console.WriteLine(array);
}

Console.WriteLine("Enter the index number you want to display");


Console.WriteLine("Index NUmber of Table: ");
int table1 = int.Parse(Console.ReadLine());
Console.WriteLine("Index NUmber of Row: ");
int row1 = int.Parse(Console.ReadLine());
Console.WriteLine("Index NUmber of Col: ");
int col1 = int.Parse(Console.ReadLine());

Console.WriteLine("Element is: " + anArray[table1,row1,col1]);


}

Display all arrays:


int[,,] anArray = new int[2, 2, 2]
{
{
{1, 2},
{3, 4}
},
{
{5, 6},
{7, 8}
}
};

for (int table=0; table< anArray.GetLength(0);table++)


{
for (int row=0; row< anArray.GetLength(1); row++)
{
for (int col = 0; col < anArray.GetLength(2); row++)
{
Console.WriteLine(anArray[table, row, col]);
}
}
}

Вам также может понравиться