C program to find addition of lower triangular elements

C program to find addition of lower triangular elements:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>

 main()
 {
   int i,j,a[10][10],sum,rows,columns;

   printf("Enter the number of Rows : ");
   scanf("%d",&rows);

   printf("\nEnter the number of Columns : ");
   scanf("%d",&columns);

   //Accepting the Elements in Matrix
   printf("\nEnter %d*%d Matrix:\n",rows,columns);
   for(i=0;i<rows;i++)
      {
      for(j=0;j<columns;j++)
        {
         scanf("%d",&a[i][j]);
        }
      }

   //Addition of the Diagonal Elements
   sum = 0;
   for(i=0;i<rows;i++)
    {
      for(j=0;j<columns;j++)
        {
         if(i > j)
         {
            sum=sum + a[i][j];
         }
       }
    }
   //Printing the result
   printf("\nSum of Lower Triangle Elements is: %d",sum);
}

OUTPUT:

Enter the number of Rows : 3

Enter the number of Columns : 3

Enter 3*3 Matrix:
12 41 25
31 21 17
18 25 41

Sum of Lower Triangle Elements is: 74

 

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty − 16 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.