#include <stdio.h>
int main ()
{
int row,col,m[50][50],u_sum=0,l_sum=0;
printf("Enter number of row:\n");
scanf("%d",&row);
printf("Enter number of column:\n");
scanf("%d",&col);
int i,j;
printf("Enter values:\n");
for(i=0;i<row;i++) //input
{
for(j=0;j<col;j++)
{
scanf("%d",&m[i][j]);
}
}
for(i=0;i<row;i++) //upper triangle sum
{
for(j=i+1;j<col;j++)
{
u_sum=u_sum+m[i][j];
}
}
for(i=1;i<row;i++) //lower triangle sum
{
for(j=0;j<i;j++)
{
l_sum=l_sum+m[i][j];
}
}
printf("Upper Triangle Sum: %d\n",u_sum);
printf("Lower Triangle Sum: %d\n",l_sum);
return 0;
}
No comments:
Post a Comment