#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,a[10][10],sum,m,n;
printf("\ninsert lines : ");
scanf ("%d",&m);
printf("\ninsert columns : ");
scanf ("%d",&n);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("insert values : ",i,j);
scanf("%d",&a[i][j]);
}
sum = 0;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if ( i < j )
sum = sum + a[i][j];
}
printf("\nmatrix\n");
for(i=0;i<3;i++)
{
printf("\n");
for(j=0;j<3;j++)
printf("%d\t",a[i][j]);
}
printf("\nsum of above main diagonal values : %d",sum);
getchar();
getchar();
return 0;
}
So I have this code but I can't figure out how to add only negative values in the matrix. So I insert for example 1 -2 -3
4 5 6
7 8 9
it gets 1 for the awnser but it should get -5.Also i can't seem to make it work using while instead of for loop.