37. SUM OF DIAGONAL ELEMENTS OF A MATRIX
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
for(j=0;j
scanf("%d",&a[i][j]);
printf("\nThe matrix is\n");
for(i=0;i
{
printf("\n");
for(j=0;j
{
printf("%d\t",a[i][j]);
}
}
for(i=0;i
{
for(j=0;j
{
if(i==j)
sum=sum+a[i][j];
}
}
printf("\n\nSum of the diagonal elements of a matrix is -> ");
printf("%d",sum);
getch();
}
No comments:
Post a Comment
Thanks to given comments.......