C Program To Find Addition Of Lower Triangular Elements(2D-Array)

C Program To Find Addition Of Lower Triangular Elements(2D-Array)

#include<stdio.h>

int main()
{

   int i, j, a[10][10], sum, rows, columns;

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

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

   for (i = 0; i < rows; i++)
   {
      for (j = 0; j < columns; j++)
 {
         printf("Enter the Element a[%d][%d] : ", i, j);
         scanf("%d", &a[i][j]);
      }
   }

 //add digonal element
   sum = 0;
   for (i = 0; i < rows; i++)
   {
      for (j = 0; j < columns; j++)
 {
         // Condition for Lower Triangle
         if (i > j)
{
            sum = sum + a[i][j];
         }
      }
   }

   printf("Sum of Lower Triangle Elements : %d\n", sum);     //Print out the Result(sum)
 
}

Related Posts