Subject content:
Write function void fun (int t [M] [N], int p [N]), line point t a M N columns of two-dimensional arrays, and the two dimensional array smallest elements in each column, and in turn into a one-dimensional array p, two-dimensional array of data given in the main function, and each column of the smallest element in the output of the main function, define symbolic constant M is 5, symbolic constant N is 6,
CodePudding user response:
Conveniently wrote a, consult5 # define M
# define N 6
Void fun (int t [M] [N], int p [N])
{
Int r, c, m;
For (c=0; C{
M=t [0] [c];
For (r=1; r{
If (t [r] [c]{
M=t [r] [c];
}
}
P=m [c];
}
}
Int main ()
{
Int r, c, t [M] [N]={0}, p={0} [N].
For (r=0; r{
For (c=0; C{
The scanf (" % d ", & amp; T [r] [c]);
}
}
Fun (t, p);
For (c=0; CPrintf (" % d ", p [c]);
return 0;
}
CodePudding user response:
A one-dimensional array to use the first line of the two-dimensional array populated, and fixed n a good
# include & lt; stdio.h>
# define M 5
# define N 6
Void fun (int t [M] [N], int p [N]) {
Int I=0, j=0;
for(i=0; IP=t [0] [I] [I];
}//assignment, if you will be a pointer can point to the first line directly
for(j=0; Jfor(i=0; I If (p [j] & gt; [I] [j])=t
{
P=t [j] [I] [j];
}
}
}
}
Int main () {
int i=0; Int j=0;
Int t [M] [N]={};
Int [N] p={};
for(i=0; Ifor(j=0; J The scanf (" % d ", & amp; T [I] [j]);
}
}
Fun (t, p);
for(i=0; IPrintf (" % d ", p [I]);
}
printf("\n");
return 0;
}
Upstairs directly define m is also a principle, that is, to the back of the comparison