Sandeep Banerjee

Sandeep Banerjee

  • NA
  • 249
  • 264k

Identity matrix in C#

Mar 7 2015 4:10 PM
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<i; row++)
{
for(col = 0; col<j; col++)
matA[row,col]= Convert.ToInt16(Console.ReadLine());
Console.WriteLine();
}
Console.WriteLine("\nMatrix A: ");
for(row=0; row<i; row++)
{
for(col = 0; col<j; col++)
Console.Write("{0:D2} ", matA[row,col]);
Console.WriteLine();
}
for(row = 0; row < i; row++)
{
for(col = 0; col<j; 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 
 
 
 

Answers (2)