Blogger Widgets


C# program to prints an identity matrix using for loop
C# program which prints an identity matrix using for loop

Program statement:
Write a program which prints an identity matrix using for loop i.e. takes value n from user and show the identity table of size n * n.

Solution:
static void Main(string[] args)
{
int n,i,j;
Console.WriteLine("Enter value of n:");
n = Convert.ToInt32(Console.ReadLine());
int[,] arr=new int[n,n];

for (i = 0; i < n; i++)
{
for (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();
}



C# program to prints an identity matrix using for loop
01 Dec 2013

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top