GoogelAddUnit1

Monday 16 April 2012

WRITE A C-PROGRAM TO PRINT THE UPPER TRIANGLE,LOWER TRIANGLE&DIAGONAL SUMS.

WRITE A C-PROGRAM TO PRINT THE UPPER TRIANGLE,LOWER TRIANGLE&DIAGONAL SUMS.
AIM:A program to find the upper triangle,lower triangle,diagonal sums.
PROGRAM:
#include<stdio.h>
main()
{
int a[10][10],i,j,m,n,usum=0,lsum=0,dsum=0;
printf("enter the values of m,n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(i<j)
usum=usum+a[i][j];
else
if(i>j)
lsum=lsum+a[i][j];
else
if(i==j)
dsum=dsum+a[i][j];
printf("upper triangle sum=%d",usum);
printf("lower triangle sum=%d",lsum);
printf("diagonal sum=%d",dsum);
}
OUTPUT:
enter the values of m,n
3,3
enter the elements of matrix a
3 4 5
1 2 3
4 3 2
uppre triangle sum=
lower triangle sum=
diagonal sum=

No comments:

Post a Comment