C Program to find sum of lower triangle matrix
Program
#include<stdio.h>
void main()
{
int i, j, a[10][10], sum, rows, columns;
printf("Enter the number of Rows :\t");
scanf("%d", &rows);
printf("Enter the number of Columns :\t");
scanf("%d", &columns);
for (i = 0; i < rows; i++)
{
for (j = 0; j < columns; j++)
{
printf("Enter the Element a[%d][%d] :\t", i, j);
scanf("%d", &a[i][j]);
}
}
for (i = 0; i < rows; i++)
{
for (j = 0; j < columns; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
sum = 0;
for (i = 0; i < rows; i++)
{
for (j = 0; j < columns; j++)
{
if (i > j)
{
sum = sum + a[i][j];
}
}
}
printf("\nSum of Lower Triangle Elements : %d\n", sum);
}
Output
Enter the number of Rows : 3
Enter the number of Columns : 3
Enter the Element a[0][0] : 65
Enter the Element a[0][1] : 12
Enter the Element a[0][2] : 6
Enter the Element a[1][0] : 32
Enter the Element a[1][1] : 90
Enter the Element a[1][2] : 76
Enter the Element a[2][0] : 45
Enter the Element a[2][1] : 76
Enter the Element a[2][2] : 1
65 12 6
32 90 76
45 76 1
Sum of Lower Triangle Elements : 153