// C# program to find trace and normal
// of given matrix
using System;
class GFG {
// Returns Normal of a matrix of
// size n x n
static int findNormal(int [,]mat, int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
sum += mat[i,j] * mat[i,j];
return (int)Math.Sqrt(sum);
}
// Returns trace of a matrix of size
// n x n
static int findTrace(int [,]mat, int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += mat[i,i];
return sum;
}
// Driven source
public static void Main ()
{
int [,]mat = { {1, 1, 1, 1, 1},
{2, 2, 2, 2, 2},
{3, 3, 3, 3, 3},
{4, 4, 4, 4, 4},
{5, 5, 5, 5, 5},
};
Console.Write ("Trace of Matrix = "
+ findTrace(mat, 5) + "\n");
Console.Write("Normal of Matrix = "
+ findNormal(mat, 5));
}
}
// This code is contributed by nitin mittal.