প্রথমে, একটি দ্বি-মাত্রিক অ্যারে সেট করুন৷
int[,] arr = new int[10, 10];
এখন, ব্যবহারকারীর থেকে উপাদানগুলি পান -
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
arr[i, j] = Convert.ToInt16(Console.ReadLine());
}
} ম্যাট্রিক্স প্রদর্শনের সম্পূর্ণ উদাহরণ দেখা যাক।
উদাহরণ
using System;
using System.Linq;
class Demo {
static void Main() {
int m, n, i, j;
// rows and columns of the matrix+
m = 2;
n = 2;
int[,] arr = new int[10, 10];
Console.Write("Enter elements of the Matrix: ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
arr[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.WriteLine("Printing Matrix: ");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
Console.Write(arr[i, j] + "\t");
}
Console.WriteLine();
}
Console.ReadLine();
}
} আউটপুট
নিচের আউটপুট।
Enter elements of the Matrix: 5 10 12 15 Printing Matrix: 510 1215