To input a square matrix and calculate sum of



To input a square matrix and calculate sum of
1. Diagonal element
2. Lower triangular elements
3. Upper triangular elements

#include
#include

main()
{
int a[5][5],i,j,m,n,s=0,sl=0,su=0;
clrscr();
printf("Input array size ");
scanf("%d%d",&m,&n);
if(m==n)
{
printf("\nInput %d elements ",m*n);
for(i=0;ifor(j=0;jscanf("%d",&a[i][j]);
clrscr();
printf("\nEntered array is \n");
for(i=0;i{
for(j=0;j{
printf("%d",&a[i][j]);
if(i==j)
s=s+a[i][j];
if(isu=su+a[i][j];
if(i>j)
sl=sl+a[i][j];
}
printf("\n");
}
printf("\nSum of diagonal elements = %d",s);
printf("\nSum of upper triangular matrix is %d",su);
printf("\nsum of lower triangular matrix is %d",sl);
}
else
printf("\nWrong dimensions, not a square array ...");
}

No comments:

Post a Comment