0 votes
417 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 327 views
0 votes
1 answer 418 views
0 votes
1 answer 430 views
0 votes
1 answer 120 views
0 votes
1 answer 225 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

554 users

...