C Programming Code Examples C > Arrays and Matrices Code Examples C Program to Find the Trace & Normal of a given Matrix C Program to Find the Trace & Normal of a given Matrix This C Program find the trace & normal of a given matrix. Here trace of the matrix is the sum of the elements of the main diagonal i.e the diagonal from the upper left to the lower right of a matrix. Normal of the matrix is the square root of the sum of all the elements. /* * C program to find the trace and normal of a matrix * Trace is defined as the sum of main diagonal elements and * Normal is defined as square root of the sum of all the elements */ #include <stdio.h> #include <math.h> void main () { static int array[8][8]; int x, j, m, n, sum = 0, sum1 = 0, a = 0, normal; printf("Enter the order of the matrix\n"); scanf("%d %d", &m, &n); printf("Enter the n coefficients of the matrix \n"); for (x = 0; x < m; ++x) { for (j = 0; j < n; ++j) { scanf("%d", &array[x][j]); a = array[x][j] * array[x][j]; sum1 = sum1 + a; } } normal = sqrt(sum1); printf("The normal of the given matrix is = %d\n", normal); for (x = 0; x < m; ++x) { sum = sum + array[x][x]; } printf("Trace of the matrix is = %d\n", sum); }