Home > Back-end >  C, please help've picked, m a student n courses, the two-dimensional array and pointer
C, please help've picked, m a student n courses, the two-dimensional array and pointer

Time:10-28


# include & lt; Stdio. H>
# define STUD 30
5 # define COURSE
Void Total (int * score, int sum [], float aver [], int m, int n);
Void Print (int * score, int sum [], float aver [], int m, int n);
Int main (void)
{
Int I, j, m, n, score [STUD] [running], the sum (STUD); Float aver [STUD];
Printf (" How many courses? \n"); The scanf (" % d ", & amp; n);
Printf (" How many students? \n"); The scanf (" % d ", & amp; m);
Printf (" Input scores: \ n ");
for(i=0; i{
for(j=0; j{printf (" Input scores: \ n "); The scanf (" % d ", & amp; Score [I] [j]);
}
}
The sum Total (* score, aver, m, n); Print (* score, sum, aver, m, n);
return 0; }
PScore void Total (int * and an int sum [], float aver [], int m, int n)
{
int i,j;
for(i=0; i{sum [I]=0;
for(j=0; j{
Sum [I]=sum pScore [I] + [I * n + j];
}
Aver [I]=sum (float) [I]/n;
}
}
PScore void Print (int * and an int sum [], float aver [], int m, int n)
{
int i,j;
Printf (" Result: \ n ");
for(i=0; i{
for(j=0; j{
Printf (" % 4 d \ t, "pScore [I * n + j]);
} printf (" % 5 d \ t % 6.1 lf \ n ", sum [I], aver [I]);
}
}

CodePudding user response:

The problem here:
Score [STUD] [running]

So
for(j=0; j{
Sum [I]=sum pScore [I] + [I * n + j];
}
Is wrong
Sum [I]=sum pScore [I] + [I * COURSE + j];

Such ability can
The following Print function is the same problem

CodePudding user response:

Column a pointer is an array of the number of columns for each of the mobile, the original array line corresponding row pointer course is several times? The memory of those empty array is empty
The book says column pointer is equivalent to the two dimensional array as a one-dimensional array
According to this problem is a string of number in discontinuous luo

CodePudding user response:

Int a [2] [3]={6};
A [0]=={1, 2, 3} [0] a [0]==1 a [0] [1]==2 a [0] [2]==3
A [1]=={4 and 6} [1] a [0]==4 a [1] [1]==5 a [1] [2]==6

Two-dimensional array like excel spreadsheet, with two rows and columns to determine the specific position,

CodePudding user response:

refer to the second floor m0_46218308 response:
column pointer is an array of the number of columns for each of the move, the original row pointer array line of course is several times? The memory of those empty array is empty
The book says column pointer is equivalent to the two dimensional array as a one-dimensional array
According to this problem is a string of number in discontinuous luo


Int score [STUD] [running]; This is the original definition
Memory structure is STUD on the length of one by one, the COURSE of a one-dimensional array of storage, can be used as a one-dimensional array to no problem
Score [I] [j] in distance score the first address of memory is the I * COURSE
So when using one dimensional array, are to be calculated according to the position