Program for Sum of Diagonal Elements of a Square Matrix
#include<stdio.h> #include<conio.h> main ( ) { int a [10][10],m, n, i, j, s=0; printf ( “enter number of rows and co...
https://www.computersprofessor.com/2016/06/program-for-sum-of-diagonal-elements-of.html?m=0
#include<stdio.h>
#include<conio.h>
main
( )
{
int
a [10][10],m, n, i, j, s=0;
printf
( “enter number of rows and columns”);
scanf
(“%d%d”, & m, & n);
printf
( “enter elements into an array”);
for
( i = 0; i < m; i ++)
{
for (j=0; j < m; j ++)
{
scanf(“%d”,&a[i][j]);
}
}
for
( i = 0; i < m, i ++)
{
for ( j = 0; j < n; j ++)
{
If (
i = = j)
{
s=s +a [i][j];
}
}
}
printf(”\n
sum of diagonal elements is %d”, s);
getch
( );
}