Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4.  
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. void change() {
  11.     int n, max = -10000, index, third, k, m;
  12.     cout << "Enter the size of array:";
  13.     cin >> n;
  14.     int A[n][n];
  15.     for (int i = 0;i < n; i++) {
  16.         for (int j = 0;j < n; j++) {
  17.             cin >> A[i][j] ;
  18.             if (A[i][j] > max ) {
  19.                 max = A[i][j];
  20.                 index = j;
  21.             }
  22.             if (j == n - 1) {
  23.                 third = A[i][i];
  24.                 A[i][i] = max;
  25.                 A[i][index] = third;
  26.                 max = -10000;
  27.             }
  28.         }
  29.     }
  30.     //cout << i;
  31.     for (m = 0;m < n; m++) {
  32.         for (int l = 0;l < n; l++) {
  33.             cout << A[m][l] << " \t ";
  34.         }
  35.         cout << endl;
  36.     }
  37. }
  38.  
  39.  
  40. int main()
  41. {
  42.     change();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement