# C Program Calculate Sum of Upper and Lower Triangle of a Matrix

by Dinesh Thakur Category: C Programming (Pratical)

In this program user ask to make sum of upper and lower triangle of matrix. In this program user declare the array type Variable after declaring value to the variable if statement will be use to check whether the matrix is square or not. Else it will be going to enter elements for matrix. Loop statement will use to calculate the procedure for elements. For loop and control statements will use the procedure to make it. Then a print method will use to display the sum of upper triangle.

Next move is to calculate the sum of lower matrix triangle as per procedure. Here the same logic use to calculate the sum of lower matrix triangle along with using loop statement and control statement and to get the result in the end.
Problem Statement:-
This program is an implementation about to calculate the sum of lower and upper triangle matrix.

1. Enter the matrix elements.
2. Checks the mode of matrix.
3. Display the result on screen.

This C program is successfully compiled and run on a System. Output is shown below.

```#include<stdio.h>void main(){     int a[10][10],sum=0,sm=0;     int i,j,m,n;     clrscr();     printf("Enter Order of Matrix : ");     scanf("%d%d",&m,&n);     if(m!=n)       {           printf("Not a Square Matrix : ");           getch();           exit();       }           printf("Enter Elements : ");           for(i=0;i<m;i++)               {                  for(j=0;j<n;j++)                      {                          scanf("%d",&a[i][j]);                      }               }                  for(i=0;i<m;i++)                      {                          for(j=0;j<n;j++)                              {                                  if(i+j<m-1)                                    {                                         sum+=a[i][j];                                    }                               }                      }                          printf("\n Sum of Upper Triangle is : %d",sum);                          for(i=0;i<m;i++)                              {                                  for(j=0;j<n;j++)                                      {                                         if(i+j>m-1)                                           {                                                sm+=a[i][j];                                            }                                       }                              }                                   printf("\n Sum of Lower Triangle is : %d",sm);                                   getch();}
```

Related Articles C Programming

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content