Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Input the elements of a three-dimensional plastic array, and output the maximum value, minimum value and subscripts of its rows and columns. How to use C++ programming?
Input the elements of a three-dimensional plastic array, and output the maximum value, minimum value and subscripts of its rows and columns. How to use C++ programming?
This is actually not difficult, like a two-dimensional array. You only need to understand it in two dimensions, and you can come out by thinking hard.

The process is as follows:

# include & ltiostream.h & gt

# Define n 2

# Define m 2

# Define l 2

void main()

{

int shuz[n][m][l],I,j,k;

int max,min,maxx,maxy,maxz,minx,miny,minz

Cout & lt& lt Please enter a three-dimensional array which is

for(I = 0; I & ltn;; I++)// Enter a three-dimensional array.

for(j = 0; j & ltm; j++)

for(k = 0; k & ltl; k++)

CIN & gt; & gtshuz[I][j][k];

for(I = 0; I & ltn;; I++)// Output a three-dimensional array.

{

for(j = 0; j & ltm; j++)

{

for(k = 0; k & ltl; k++)

cout & lt& ltshuz[I][j][k]& lt; & lt" ";

cout & lt& lt" ";

}

cout & lt& ltendl

}

cout & lt& ltendl

max = shuz[0][0][0];

maxx = 0;

maxy = 0;

maxz = 0;

for(I = 0; I & ltn;; I++)// Find the maximum value and its subscript.

for(j = 0; j & ltm; j++)

for(k = 0; k & ltl; k++)

if(shuz[I][j][k]& gt; Max)// If there is something bigger than it, assign it accordingly.

{

maxx = I;

maxy = j;

maxz = k;

max = shuz[I][j][k];

}

Cout & lt& lt "Maximum quantity is"

Cout & lt& lt its subscript is: "<&l tmaxx & lt<" "<< maxy & lt" "<< maxz & lt< endl.

minx = 0;

miny = 0;

minz = 0;

min = shuz[0][0][0];

for(I = 0; I & ltn;; I++)// Find the minimum value and its subscript.

for(j = 0; j & ltm; j++)

for(k = 0; k & ltl; k++)

if(shuz[I][j][k]& lt; Min)// If there is something smaller than it, assign it accordingly.

{

minx = I;

miny = j;

minz = k;

min = shuz[I][j][k];

}

Cout & lt& lt "Minimum quantity is"

Cout & lt& lt its subscript is: "<< crazy girl & lt<" "<< miny & lt" "<< minz & lt< endl.

}

You can ask me again if you don't understand! ! ! !