Friday, June 10, 2011

FIND OUT SUM OF DIAGONAL ELEMENTS OF A MATRIX USING

#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;
}

2 comments:

  1. what if we want to add the elements of diagonal from right to left...
    please mail the solution on
    tarun16feb@gmail.com

    ReplyDelete
  2. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! find lcm of two numbers in c

    ReplyDelete