Accept the value for multidimensional array from user and print the it in matrix format.
using System;namespace testArray
{
class Program
{
static void Main(string[] args)
{Console.WriteLine("Enter the value for multidimensional array:");
int[,] arr1 = new int[3, 2];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
arr1[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.WriteLine("Displaying the multidimensional array in matrix format :");
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
Console.Write(arr1[i, j] +" ");
}
Console.WriteLine( "\n");
}
Console.ReadKey();
}
}
}
Output:-
Enter the value for multidimensional array:
2
3
5
9
1
0
Displaying the multidimensional array in matrix format :
2 3
5 9
1 0
No comments:
Post a Comment