Math, asked by gouda7417, 10 months ago

Display the sum of the diagonal elements in the matrix

Answers

Answered by joybiswas100
0

Answer:

Elements of a Matrix

In this article, we will show you, How to write a C Program to find Sum of Diagonal Elements of a Matrix. Or How to write a C program to find Sum of Diagonal Elements of a Multi-Dimensional Array with example.

C Program to find Sum of Diagonal Elements of a Matrix 2

C Program to find Sum of Diagonal Elements of a Matrix

This program allows the user to enter the number of rows and columns of a Matrix. Next, we are going to calculate the sum of diagonal elements in this matrix using For Loop.

/* C Program to find Sum of Diagonal Elements of a Matrix */

#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;

Similar questions