-
Notifications
You must be signed in to change notification settings - Fork 27
/
Normal and Trace of a Square Matrix
39 lines (33 loc) · 1.09 KB
/
Normal and Trace of a Square Matrix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include<stdio.h>
/*
to use the sqrt method to find
the square root of a number we include
math.h header file
*/
#include<math.h>
int main()
{
printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
int i, j, n, aj[10][10], sum = 0, sum1 = 0, a = 0, normal;
printf("\nEnter the number of rows (columns) of the matrix: \n\n");
scanf("%d", &n);
printf("\nEnter the %d elements of the first matrix: \n\n", n*n);
for(i = 0; i < n; i++) // to iterate the rows
{
for(j = 0; j < n; j++) // to iterate the columns
{
scanf("%d", &aj[i][j]);
a = aj[i][j]*aj[i][j]; // finding square of each element
sum1 += a; // same as sum1 = sum1 + a
}
}
normal = sqrt((double)sum1); // typecasting to double value
printf("\n\nThe normal of the given matrix is: %d", normal);
for(i = 0; i < n; i++)
{
sum = sum + aj[i][i]; // sum of the diagonal elements
}
printf("\n\nThe Trace of the given matrix is: %d", sum);
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}