Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Find the maximum and minimum values in a two-dimensional array. . . C language writing
Find the maximum and minimum values in a two-dimensional array. . . C language writing
# include & ltstdio.h & gt

int main(int argc,const char * argv[])

{

int arr[3][4]={34, 13,45,67,42,78,56, 10,58,45,78,98 };

int arr 1[3][4];

for(int I = 0; I<3; I++)// Output all elements.

{

for(int j = 0; j & lt4; j++)

{

printf("%d\t ",arr[I][j]);

}

printf(" \ n ");

}

for(int I = 0; I<3; I++)// assignment operation, make its position the same.

{

for(int j = 0; j & lt4; j++)

{

arr 1[I][j]= arr[I][j];

}

}

//Determine the maximum quantity

for(int I = 0; I<3; i++)

{

for(int j = 0; j & lt4; j++)

{

if(arr[0][0]& lt; arr[i][j])

{

int temp = arr[0][0];

arr[0][0]= arr[I][j];

arr[I][j]= temp;

}

}

}

Printf ("Maximum quantity: %d\n", arr [0] [0]);

//Determine the position of the maximum number

for(int I = 0; I<3; i++)

{

for(int j = 0; j & lt4; j++)

{

if (arr[0][0]==arr 1[i][j])

{

Printf ("on line %d, column %d \n", i, j);

}

}

}

//Determine the minimum quantity

for(int I = 0; I<3; I++)// Judge the minimum number.

{

for(int j = 0; j & lt4; j++)

{

if (arr[0][0]>arr[i][j])

{

int temp = arr[0][0];

arr[0][0]= arr[I][j];

arr[I][j]= temp;

}

}

}

Printf ("minimum number: %d\n", arr [0] [0]);

//Determine the position of the smallest number

for(int I = 0; I<3; i++)

{

for(int j = 0; j & lt4; j++)

{

if (arr[0][0]==arr 1[i][j])

{

Printf ("on line %d, column %d \n", i, j);

}

}

}

Returns 0;

}

Extended data:

Printing usage

Print (x, y)

be equal to

Import system

sys . stdout . write(str(x)+' '+str(y)+' \ n ')

Syntactically, the print function calling python3.0 has the following form:

Print ([object, ...] [,seq=''][, end='\n'][, file=sys.stdout])

Seq is to insert a string between the texts of each object. If there is no pile bottom, the default is a single space, and the empty string passed is always a delimiter.

End is a string added at the end of printed text. If it is not passed, it is a newline character by default. Passing a control string will avoid moving to the next input line at the end of the printed text-the next print will remain added to the end of the current output line.

File specifies the file, standard stream, or other file-like object to which the text will be sent. If it is not passed, it defaults to sys.stdout, and any object with a write(string) method similar to a file can be passed, but the actual file should have opened the output.