Wrtie C program to find the trace and normal of a matrix.

Here is source code of the C program to find the trace & normal of a given matrix. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
  1. /*
  2.  * C program to find the trace and normal of a matrix
  3.  *
  4.  * Trace is defined as the sum of main diagonal elements and
  5.  * Normal is defined as square root of the sum of all the elements
  6.  */
  7. #include <stdio.h>
  8. #include <math.h>
  9.  
  10. void main ()
  11. {
  12.     static int array[10][10];
  13.     int i, j, m, n, sum = 0, sum1 = 0, a = 0, normal;
  14.  
  15.     printf("Enter the order of the matrix\n");
  16.     scanf("%d %d", &m, &n);
  17.     printf("Enter the n coefficients of the matrix \n");
  18.     for (i = 0; i < m; ++i)
  19.     {
  20.         for (j = 0; j < n; ++j)
  21.         {
  22.             scanf("%d", &array[i][j]);
  23.             a = array[i][j] * array[i][j];
  24.             sum1 = sum1 + a;
  25.         }
  26.     }
  27.     normal = sqrt(sum1);
  28.     printf("The normal of the given matrix is = %d\n", normal);
  29.     for (i = 0; i < m; ++i)
  30.     {
  31.         sum = sum + array[i][i];
  32.     }
  33.     printf("Trace of the matrix is = %d\n", sum);
  34. }

0 comments:

Feel free to contact the admin for any suggestions and help.