-
In C, here's the main part.
int x,y,x_max,y_max,max;
int a[m,k];
max=0;
for(x=0;x<=m;x++)
for(y=0;y<=k;y++)
if(i>max)
max=a[x,y];
x_max=x;
y_max=y;
The resulting max is the maximum, and (x max, y max) is the position of the maximum.
-
# include
# define m 10
# define n 5
void main()
int a[m][n];
int i,j,row=0,col=0;
int *p;
p=&a[0][0];
for(i=0;ifor(j=o;j Enter data.
for(i=0;ifor(j=o;jif(*pp=&a[i][j];
row=i+1;
col=j+1;
Determine the size of the number referred to by p and the current number, and if it is small, change the pointing of p to ensure that it always points to the largest number. Since the subscript starts at 0, add 1 to the rows and columns of the output.
printf("the largest num is %d;it is in %drow,%dcol",*p,row,col);
-
The calculation is to divide the number of elements in the array by the number in the second dimension, if there is a remainder.
Then the quotient +1 is the size of the first dimension, and the quotient without remainder is the size of the first dimension. For example, in your example, 9 4 = 2 and 1 remains, then 2 + 1 = 3, and the size of the first dimension is 3The rest is not set, and the system will depend on the data type.
Automatic value assignment. <>
-
The calculation method is: divide the number of elements of the array by the number of the second dimension, if there is a remainder, then the quotient +1 is the size of the first dimension, and the quotient without a remainder is the size of the first dimension. For example, in your example, 9 4 = 2 and 1 remains, then 2 + 1 = 3, and the size of the first dimension is 3
If the rest is not set, the system will automatically assign values based on the data type.
-
Numeric index, incrementing from zero.
The two-dimensional array name a is a pointer to a pointer. It is also a pointer array name, which contains 3 elements, a[0]a[1], a[2]. Although the address stored by a is the address of the first element of the array, it does not point to a variable, but to a pointer. >>>More
In fact, if you have read "C Expert Programming", it is very simple, and this problem has been carefully described above. It's stored in memory as shown in the figure. n[0][5] is actually *(*n+0)+5), which is the sixth cell. >>>More
If you want to learn systematically, you can consider signing up for a live online class, and recommend CGWANG's online class. The teacher speaks carefully, you can watch it back after the class, and there are also the same type of recorded classes that you can learn for free (give away lifelong VIP). >>>More
One-dimensional arrays hold the same values, but in the case of matrices, determinants. >>>More
1 Maximum number of subscript elements - 1
2 Precautions for use: >>>More