C# program which prints an identity matrix using beneficial to loop
Program statement:
Write a program which prints an identity matrix using beneficial to loop i.e. takes value n from user furthermore show the identity table regarding size n * n.
Solution:
static void Main(string[] args)
{
int n,i,j;
Console.WriteLine("Enter value regarding n:");
n = Convert.ToInt32(Console.ReadLine());
int[,] arr=new int[n,n];
beneficial to (i = 0; i < n; i++)
{
beneficial to (j = 0; j < n; j++)
{
if (i == j)
arr[i, j] = 1;
else
arr[i, j] = 0;
Console.Write(arr[i, j]);
}
Console.WriteLine();
}
Console.ReadLine();
}