FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX USING

FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX USING


Solution:


#include<stdio.h>
int main(){
  int a[10][10],i,j,sum=0,m,n;
  printf("\nEnter the row and column of matrix");
  scanf("%d %d",&m,&n);
  printf("\nEnter the First matrix->");
  for(i=0;i<m;i++)
      for(j=0;j<n;j++)
           scanf("%d",&a[i][j]);
  printf("\nThe matrix is\n");
  for(i=0;i<m;i++){
      printf("\n");
      for(j=0;j<m;j++){
      printf("%d\t",a[i][j]);
      }
 }
 for(i=0;i<m;i++){
     for(j=0;j<n;j++){
          if(i==j)
              sum=sum+a[i][j];
     }
 }
 printf("\n\nSum of the diagonal elements of a matrix is -> ");
 printf("%d",sum);
 return 0;
}

More C Program :


  1. FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX USING
  2. sum of both diagonal elements of a matrix in c
  3. sum of diagonal elements of a matrix in java
  4. sum of diagonal elements of a matrix in c++
  5. sum of right diagonal matrix in c
  6. program to calculate sum of diagonals of a matrix
  7. sum of diagonal elements of a matrix in matlab
  8. diagonal elements of a matrix python
  9. sum of diagonal elements of a square matrix


Learn More :