Write the c program to calculate the sum of element of upper triangle of nXn matrix

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],r,c;
int i=0,j=0,sum=0;
clrscr();
printf("\n enter the r and c");
scanf("%d%d",&r,&c);
printf("\n enter the array\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n enter the array\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("\t%d",a[i][j]);
}
printf("\n");
}
printf("\n sum of upper triangle\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(i<=j)
sum=sum+a[i][j];
}
}
printf("\n sum of upper tringle=%d",sum);
getch();
}

Comments