SHARE
TWEET

Untitled

a guest Dec 8th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     const int n = 4;
  7.     int A[n][n] = {
  8.         {2,3,3,4},
  9.         {5,2,1,6},
  10.         {7,2,3,4},
  11.         {8,6,4,9}
  12.     };
  13.     int max, max_x, max_y, min, min_x, min_y;
  14.     max = A[0][0];
  15.     min = A[0][0];
  16.     for (int i = 0; i < n; i++) {
  17.         for (int j = 0; j < n; j++) {
  18.             if (abs(A[i][j]) > max) {
  19.                 max = A[i][j];
  20.                 max_x = i;
  21.                 max_y = j;
  22.             }
  23.             if (abs(A[i][j]) < min) {
  24.                 min = A[i][j];
  25.                 min_x = i;
  26.                 min_y = j;
  27.             }
  28.         }
  29.     }
  30.     A[min_x][min_y] = max;
  31.     A[max_x][max_y] = min;
  32.     for (int i = 0; i < n; i++) {
  33.         for (int j = 0; j < n; j++) {
  34.             cout << A[i][j] << " ";
  35.         }
  36.         cout << endl;
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top