![]() |
VOOZH | about |
Here, we will see how to write a C program to find the normal and trace of a matrix. Below are the examples:
Input: mat[][] = {{1, 2, 3},
{4, 5, 6},
{7, 8, 9}};
Output:
- Normal = 16
- Trace = 15
Explanation:
- Normal = sqrt(1*1+ 2*2 + 3*3 + 4*4 + 5*5 + 6*6 + 7*7 + 8*8 + 9*9) = 16
- Trace = 1+5+9 = 15
Input: mat[][] = {{5, 6, 1},
{7, 2, 9},
{6, 1, 3}};
Output:
- Normal = 10
- Trace = 10
Explanation:
- Normal = sqrt(5*5+ 6*6 + 1*1 + 7*7 + 2*2 + 9*9 + 6*6 + 1*1 + 3*3) = 15
- Trace = 5+2+3 = 10
For a better understanding see the below image.
Approach:
1. To Find Normal:
2. To Find Trace:
Below is the C program to find normal and the trace of a matrix:
Normal of Matrix = 16 Trace of Matrix = 15
Time Complexity: O(n*n)
Space Complexity: O(1)