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 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsForums
Top experts
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 7, 2015, 12:30 PM EST
Note that since an identity matrix is a square matrix, the number of rows and columns must be the same:
Sandeep BanerjeeRank #4,887 · 320 reputationPosted Mar 7, 2015, 5:45 PM EST