C Program to find the Sum of Upper Triangular Elements of Matrix

This page has a C Program to find the Sum of Upper Triangular Elements of Matrix. It is clear that, this C program will find the Sum of the Upper Triangular Elements of Matrix. The program is used to find the sum of the elements above the principal diagonal and the matrix elements above the principal diagonal are called Upper Triangular Elements of Matrix. The below given C program will find the Sum of Upper Triangular Elements of Matrix. Kindly check out the program to display the Sum of Upper Triangular Elements of Matrix.

Sum of Upper Triangular Elements of Matrix Program

#include<stdio.h>

int main(){

int M[20][20];

int m, n, i, j, sum=0;

printf("

Enter the Row and Column sizes of Matrix : ");

scanf("%d %d", &m, &n);

printf("



Enter the Matrix elements one by one

");

for (i = 1; i<=m; i++)

for (j = 1; j<=n; j++)

scanf("%d", &M[i][j]);

printf("

The Given Matrix is :



");

for (i = 1; i<=m; i++){

for (j = 1; j<=n; j++)

printf("\t%d ", M[i][j]);

printf("



");

}

for (i = 1; i<=m; i++){

for (j = 1; j<=n; j++)

if(i<j)

sum=sum+M[i][j];

}

printf("



The Sum of Upper Triangular elements of Matrix is %d", sum);

return(0);

} Sample Output:

Enter the Row and Column sizes of Matrix : 3 3



Enter the Matrix elements one by one

4

2

3

5

6

7

9

1

8



The Given Matrix is :



4 2 3



5 6 7



9 1 8



The Sum of Upper Triangular elements of Matrix is 12

Related Popular Posts: