sir how to check identity matrix
using System;
public class IdtMat
{
public static void Main()
{
int i, j, row, col;
int[,] matA = new int[10,10];
Console.Write("\nEnter the no. of row: ");
i=Convert.ToInt16(Console.ReadLine());
Console.Write("Enter the no. of col: ");
j=Convert.ToInt16(Console.ReadLine());
Console.WriteLine("\nEnter the Element in Matrix: ");
for(row=0; row
{
for(col = 0; col
matA[row,col]= Convert.ToInt16(Console.ReadLine());
Console.WriteLine();
}
Console.WriteLine("\nMatrix A: ");
for(row=0; row
{
for(col = 0; col
Console.Write("{0:D2} ", matA[row,col]);
Console.WriteLine();
}
for(row = 0; row < i; row++)
{
for(col = 0; col
{
if ((row == col && matA[row, col] == 1) && (row != col && matA[row, col] == 0))
{
goto lable;
}
else
{
Console.WriteLine("\n Not an Identity Matrix");
row=col=i;
}
}
}
lable: Console.WriteLine("Identity matrix");
Console.ReadLine();
}
}
this program is not working every time it prints identity matrix for the input
3 0 0
0 3 0
0 0 3
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

VulpesPosted Mar 7, 2015, 5:30 PM
Note that since an identity matrix is a square matrix, the number of rows and columns must be the same:
Sandeep BanerjeePosted Mar 7, 2015, 10:45 PM