Home > Back-end >  Why is the first line is true of the average, behind two lines is wrong, and points out that the err
Why is the first line is true of the average, behind two lines is wrong, and points out that the err

Time:09-20

An average each program for two-dimensional array
 # include & lt; Stdio. H> 
#include
Float business (int * x, int l, int j)
{
int i;
Float s=0.0;
for(i=0; i{
S=s + x (x + 4 * j + I);
}
S=s/l;
return s;
}
Int main ()
{
Int h, l, a [20] [20], I, j;
Printf (" input array lines: ");
The scanf (" % d ", & amp; H);
Printf (" input array of the number of columns: ");
The scanf (" % d ", & amp; L);
Printf (" input array: \ n ");
for(i=0; ifor(j=0; JThe scanf (" % d ", a [I] + j).
for(i=0; i{
Printf (" % d as follows: the average % f \ n ", I + 1, business (* a, l, I));
}
return 0;
}



The results

CodePudding user response:

S=s + x (x + 4 * j + I);

Why is 4 * j

Should be 20

CodePudding user response:

The
reference 1 floor? Victor.?? Response:
s=s + x (x + 4 * j + I);

Why is 4 * j

Should be 20

A two-dimensional array can not say so

CodePudding user response:

The
reference 1 floor? Victor.?? Response:
s=s + x (x + 4 * j + I);

Why is 4 * j

Should be 20

D the ij=* (d (0) + 4 * I + j)

CodePudding user response:

refer to the second floor Knight - 9 hz response:
Quote: refer to 1st floor? Victor.?? Response:
s=s + x (x + 4 * j + I);

Why is 4 * j

Should be 20

A two-dimensional array can not said it


Is it can be said, but the line length is 20, 4 to 20

CodePudding user response:

refer to the second floor Knight - 9 hz response:
Quote: refer to 1st floor? Victor.?? Response:
s=s + x (x + 4 * j + I);

Why is 4 * j

Should be 20

A two-dimensional array can not said it


1 l is right, you are a two dimensional array is fixed 20 * 20, you just doesn't work out, only 3 * 2, but do not represent each line only two elements, that is to say, each line or 20 elements, each line is your only two elements, so you calculate the address of the first element of each row, still need to use relative offset distance 20

In fact it is not necessary to put the question so complex also, no time for business, the parameters, direct pass each row of the first address is ok

 float business (int x, int l)//remove the j parameter 
{
int i;
Float s=0.0;
for(i=0; i{
S=s + * (x + I);
}
S=s/l;
return s;
}
Int main ()
{
Int h, l, a [20] [20], I, j;
Printf (" input array lines: ");
The scanf (" % d ", & amp; H);
Printf (" input array of the number of columns: ");
The scanf (" % d ", & amp; L);
Printf (" input array: \ n ");
for(i=0; ifor(j=0; JThe scanf (" % d ", a [I] + j).
for(i=0; i{
Printf (" % d as follows: the average % f \ n ", I + 1, business (a [I], l));//directly pass each row of the first address
}
return 0;
}




  • Related