10:58 AM
C++ Program to find SUM OF DIAGONAL ELEMENTS OF A MATRIX

Write a Program to find SUM OF DIAGONAL ELEMENTS OF A MATRIX

#include<iostream.h> 

#include<conio.h>
 
void main()
{
int a[10][10],i,j,sum=0,m,n;
clrscr();
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);
getch();
}
 
Note:
      If you want to change in this program please write through the comment on this page. you can also past similar program 
                 of c++ with output.your comment is valuable to the other user and person.
Views: 102 | Added by: vijoriya | Tags: find, DIAGONAL ELEMENTS, Sum, Matrix, c++, program | Rating: 0.0/0
Total comments: 0
avatar