0 votes
427 views
in C programming by (98.9k points)
edited
C Program to find Sum of Diagonal Elements of a Matrix

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include<stdio.h>
 
int main()
{
     int i, j, rows, columns, a[10][10], Sum = 0;
  
     printf("\n Please Enter Number of rows and columns  :  ");
     scanf("%d %d", &i, &j);
 
     printf("\n Please Enter the Matrix Elements \n");
     for(rows = 0; rows < i; rows++)
      {
           for(columns = 0;columns < j;columns++)
        {
              scanf("%d", &a[rows][columns]);
        }
      }
         
     for(rows = 0; rows < i; rows++)
      {
           Sum = Sum + a[rows][rows];
      }
 
     printf("\n The Sum of Diagonal Elements of a Matrix =  %d", Sum );

     return 0;
}

 

Related questions

0 votes
1 answer 337 views
0 votes
1 answer 424 views
0 votes
1 answer 437 views
0 votes
1 answer 129 views
0 votes
1 answer 240 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...