## C Program To Find Trace and Normal of Matrix

Learn How To Find Trace and Normal of Matrix in C Programming Language. The **math.h** header files includes the definitions for **sqrt()** method.

#### What is a Trace?

A Trace calculated by adding up the Main Diagonal Elements of the Matrix. The Main Diagonal Elements are the ones that occur from Top Left of Matrix Down To Bottom Right Corner.

#### What is a Normal?

A Normal is the Square Root of all the Elements in the Trace of a Matrix.

**Also Read: C Program To Find Sum of Major Diagonal Elements**

#### C Program To Find Trace and Normal of Matrix

#include<stdio.h> #include<math.h> int main () { int arr[5][5]; int i, j, normal, trace = 0, rows, columns, sum = 0, temp = 0; printf("\nEnter Number of Rows of Matrix:\t"); scanf("%d", &rows); printf("\nEnter Number of Rows of Matrix:\t"); scanf("%d", &columns); printf("\nEnter the Elements of Matrix:\n"); for(i = 0; i < rows; i++) { for(j = 0; j < columns; j++) { scanf("%d", &arr[i][j]); } } for(i = 0; i < rows; i++) { for(j = 0; j < columns; j++) { temp = arr[i][j] * arr[i][j]; sum = sum + temp; } } normal = sqrt(sum); printf("\nThe Matrix\n"); for(i = 0; i < rows; i++) { for(j = 0; j< columns; j++) { printf("%d\t", arr[i][j]); } printf("\n"); } for(i = 0; i < rows; i++) { trace = trace + arr[i][i]; } printf("\nTrace of Matrix:\t%d\n", trace); printf("\nNormal of Matrix:\t%d\n", normal); return 0; }

**Must Read: C Program To Arrange Names in Array in Alphabetical Order**

To compile this program in Linux Ubuntu, you need to type the following command:

gcc test.c -lm

#### Output

If you have any compilation errors or doubts in this C Program To Calculate Trace and Normal of Matrix, let us know about in the Comment Section below.

Thanks for this amazing c program to find normal of a matrix. I had an assignment in the college and this code helped me.

I had never heard of the concept of Trace and Normal in a Matrix before.