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...

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


Related

C Programs 2344414630626694016

Post a Comment

emo-but-icon

item