There is a two-dimensional array of 5x5, it is necessary to find the maximum and minimum elements of the array, then transfer the minimum to the beginning of the array, and the maximum to the end. Actually, below is my attempt to implement this, the problem is the incorrect output of the array itself:
#include <stdio.h> #include <conio.h> #include <math.h> int main(){ int K[5][5]; int i, j, max=40, min=-20; int iMax=0, jMax=0, iMin=0, jMin=0; int tmp; for (i=0; i<5; i++) { for (j=0; j<5; j++) { K[i][j] = min+ rand()%(max + 1 - min); } } for(i=0;i<5;i++){ for(j=0;j<5;j++) { if(K[i][j]<K[iMin][jMin]) { iMin = i; jMin = j; } if(K[i][j]>K[iMax][jMax]) { iMax = i; jMax = j; } } } tmp = K[0][0]; K[0][0] = K[iMin][jMin]; K[iMin][jMin] = tmp; tmp = K[4][4]; K[4][4] = K[iMax][jMax]; K[iMax][jMax] = tmp; for (i=0; i<5; i++) { for (j=0; j<5; j++){ printf ("%d\n", &K[i][j]); }} return 0; }