-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracenorm.c
64 lines (42 loc) · 1.23 KB
/
tracenorm.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* To find the TRACE and NORM of a given matrix A (M x N) by checking the compatibility and print both input & output matrices
with suitable headings. Use user-defined functions to find their TRACE and NORM. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX 5
int A[MAX][MAX], i, j, m, n, trace = 0, sum = 0;
float norm=0;
int main()
{
system("clear");
rep:
printf("\nEnter the Size/Order/Dim. of the Matrix-A: ");
scanf("%d %d",&m, &n);
if(m!=n)
{
printf("\nOrder of the Matrix-A must be Sqr. Matrix i.e. M = N...");
goto rep;
}
printf("\nInput %d elements into MATRIX-A: ", (m*n) );
for(i=0; i < m; i++)
for(j=0; j < n; j++)
scanf("%d",&A[i][j]);
printf("\nElements of MATRIX-A:\n");
for(i=0; i < m; i++)
{
for(j=0; j < n; j++)
printf("%d ",A[i][j]);
printf("\n");
}
//Trace of a Matrix
for(i=0; i < n; i++)
trace += A[i][i];
printf("\n Trace=%d\n",trace);
//Norm of a Matrix
for (i = 0; i < m; ++i)
for (j = 0; j < n; ++j)
sum += pow(A[i][j],2);
norm = sqrt(sum);
printf("\nNORM is %f \n", norm);
return 0;
}