/** Copyright and version statement of the program: * Copyright (c) 2012, Emy of computer science, Yantai University * All rights reserved. * file name: place the largest element in a 5*5 matrix in the center, and four corners with four smallest elements. cpp * Author: Mao Tong * Completion Date: July 15, January 16, 2013 * version number: v1.0 * description of the task and solution section: * input Description: Enter 25 numbers * Problem description: * program output: "place the largest element in a 5*5 matrix in the center, put four smallest elements in the four corners, "*/[cpp]/* put the largest element in a 5*5 matrix in the center, the four corners are respectively placed with four smallest elements (from left to right and from top to bottom in ascending order ), write a function implementation */# include <iostream> # include <iomanip> using namespace std; int main () {void Change (int * p); int a [5] [5], * p, I, j; cout <"input matrix" <endl; for (I = 0; I <5; I ++) for (j = 0; j <5; j ++) cin> a [I] [j]; p = & a [0] [0]; cout <"your input matrix is:" <endl; for (I = 0; I <5; I ++) {for (j = 0; j <5; j ++) cout <setw (6) <a [I] [j]; cout <endl ;} change (p); cout <"now matrix" <endl; for (I = 0; I <5; I ++) {for (j = 0; j <5; j ++) cout <setw (6) <a [I] [j]; cout <endl;} return 0 ;} void change (int * p) {int I, J, temp; int * pmax, * pmin; pmax = p; pmin = p; for (I = 0; I <5; I ++) // find the largest and smallest number of addresses and assign them to pmax and pmin for (j = 0; j <5; j ++) {if (* pmax <* (p + 5 * I + j) pmax = p + 5 * I + j; // * (p + 5 * I + j) when * p = a [0] [0], you can traverse the array if (* pmin> * (p + 5 * I + j )) pmin = p + 5 * I + j;} // The address with the maximum and minimum values found temp = * (p + 12 ); // swap the maximum value with the central element * (p + 12) = * pmax; * pmax = temp; temp = * p; // swap the minimum element with the element in the upper left corner * p = * pmin; * pmin = temp; pmin = p + 1; // assign the address of a [0] [1] to pmin and find the smallest element for (I = 0; I <5; I ++) for (j = 0; j <5; j ++) if (p + 5 * I + j )! = P) & (* pmin> * (p + 5 * I + j) // two conditions: the element is smaller than * pmin; the element is not the first element pmin = p + 5 * I + j; // assign the address of the second minimum value to pmin temp = * pmin; // swap the second minimum value with the element in the upper right corner * pmin = * (p + 4); * (p + 4) = temp; pmin = p + 1; // assign the address of a [0] [1] to pmin and find the smallest element for (I = 0; I <5; I ++) from this position) for (j = 0; j <5; j ++) if (p + 5 * I + j )! = P) & (p + 5 * I + j )! = (P + 4) & (* pmin> * (p + 5 * I + j) // two conditions: the element is smaller than * pmin; the element is not the first element pmin = p + 5 * I + j; // assign the address of the third minimum value to pmin temp = * pmin; // swap the third minimum value with the element in the upper right corner * pmin = * (p + 20); * (p + 20) = temp; pmin = p + 1; // assign the address of a [0] [1] to pmin and find the smallest element for (I = 0; I <5; I ++) from this position) for (j = 0; j <5; j ++) if (p + 5 * I + j )! = P) & (p + 5 * I + j )! = (P + 4) & (p + 5 * I + j )! = (P + 20) & (* pmin> * (p + 5 * I + j) // two conditions: the element is smaller than * pmin; the element is not the first element pmin = p + 5 * I + j; // assign the address of the fourth minimum value to pmin temp = * pmin; // swap the fourth minimum value with the element in the upper right corner * pmin = * (p + 24); * (p + 24) = temp;}/* running result :*/