//C program to find trace
//and normal of given matrix
#include <stdio.h>
#include<math.h>
//Return Normal of a matrix
//of size n * n
int findNormal(int mat[][3],
int n)
{
int sum=0;
//Run nested loop to access
//elements of matrix
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
sum+=mat[i][j] * mat[i][j];
return sqrt(sum);
}
//Returns trace of a matrix of
//size n * n
int findTrace(int mat[][3],int n)
{
int sum=0;
//Run nested loop to access diagonal
//elements of matrix
for(int i=0;i<n;i++)
sum+=mat[i][i];
return sum;
}
//Driver code
int main()
{
int mat[3][3]={ {1,2,3},
{4,5,6},
{7,8,9} };
printf("Normal of Matrix=%d\n",
findNormal(mat,3));
printf("Trace of Matrix=%d",
findTrace(mat,3));
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: