# Help with matrix

This is a discussion on Help with matrix within the C Programming forums, part of the General Programming Boards category; hello i got problem with this, its really simple but i dunno wheres my mistake or maybe i am copying ...

1. ## Help with matrix

hello i got problem with this, its really simple but i dunno wheres my mistake or maybe i am copying the matrixs in wrong way
i need to find the biggest element and sum up other elements in his horizontal line minus the biggest one. All this need to be copyed in new matrix with same elements but in the spot where the biggest one was i need to put the sum mentioned befor.

Code:
```#include<stdio.h>
int main()
{
int a[100][100],b[100][100],i,j,m,n,max,z=0,x=0,y=0;
printf(".........\n");
scanf("%d",&m);
scanf("%d",&n);
printf("..........\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}
max=a[0][0];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]>max)
{
max=a[i][j];
x=i;
y=j;
}
for(i=x;i=x;i=x)
for(j=0;j<n;j++)
z+=a[i][j];
z-=max;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
b[i][j]=a[i][j];
b[x][y]=z;
for(i=0;i<m;i++)
{	for(j=0;j<n;j++)
printf("%d",b[i][j]);
printf("\n");
}
return 0;
}```

2. My guess is that you are forgetting to wrap something up in braces. Any statement alone is considered to be alone, unless it is grouped by a pair of braces:
Code:
```for( ... )
this goes with the for loop;
this does not;```
Other than that, your indentation really discourages me from reading through that.

Quzah.

3. Nope, its good as it is. i only need the first statement in the loop so i can sum up the elements. I think my mistake is from 28th line ...
I want to copy the old matrix into new one but with one changed element
eg.
Code:
```                1    2    3             1    2    3
4    5    6       ->    4    5    6                   max==8; sum=-1+8+3; sum-=max; sum ==2
-1    8    3            -1    2     3```

4. Your indentation is terrible. Maybe it looks ok to you in where ever you pasted this from, but you can preview your post here you know. Or you could always hit edit.
Code:
```#include<stdio.h>
int main()
{
int a[100][100],b[100][100],i,j,m,n,max,z=0,x=0,y=0;
printf(".........\n");
scanf("%d",&m);
scanf("%d",&n);
printf("..........\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
}

max=a[0][0]; /* not attached to any loop */

for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]>max)
{
max=a[i][j];
x=i;
y=j;
}

for(i=x;i=x;i=x) /* what on earth are you doing? */
for(j=0;j<n;j++)
z+=a[i][j];

z-=max; /* not part of any loop */

for(i=0;i<m;i++)
for(j=0;j<n;j++)
b[i][j]=a[i][j];

b[x][y]=z; /* not part of any loop */

for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d",b[i][j]);
printf("\n");
}
return 0;
}```