C Program to find sum of upper 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 Upper Triangle Elements : %d\n", sum);
}
Output
Enter the number of Rows : 3
Enter the number of Columns : 3
Enter the Element a[0][0] : 98
Enter the Element a[0][1] : 47
Enter the Element a[0][2] : 26
Enter the Element a[1][0] : 27
Enter the Element a[1][1] : 11
Enter the Element a[1][2] : 8
Enter the Element a[2][0] : 37
Enter the Element a[2][1] : 74
Enter the Element a[2][2] : 86
98 47 26
27 11 8
37 74 86
Sum of Upper Triangle Elements : 81