Write a c program to calculate the sum of all upper triangle elements of a nXn matrix using DMA

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

Comments