Advertisement
printesoi

Untitled

May 9th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int N=30;
  5.  
  6. void print_matrix(int A[][N],int n,int m)
  7. {
  8.     for (int i=0;i<n;++i) {
  9.         for (int j=0;j<m;++j)
  10.             cout << A[i][j] << " ";
  11.         cout << endl;
  12.     }
  13.     cout << endl;
  14. }
  15.  
  16. int main()
  17. {
  18.     int A[N][N],i,j,lmax,lmin,cmax,cmin,max,min,n,m;
  19.  
  20.     cout << "n = ";
  21.     cin >> n;
  22.  
  23.     cout << "m = ";
  24.     cin >> m;
  25.  
  26.     for (i=0;i<n;++i)
  27.         for (j=0;j<m;++j){
  28.             cout << "A[" << i <<","<<j<<"]=";
  29.             cin >> A[i][j];
  30.         };
  31.  
  32.     print_matrix(A,n,m);
  33.    
  34.     lmax = lmin = cmax = cmin = 0;
  35.     max = min = A[0][0];
  36.  
  37.     for (i=0;i<n;++i)
  38.         for (j=0;j<m;++j) {
  39.             if (A[i][j]>max) {
  40.                 max = A[i][j];
  41.                 lmax=i;
  42.                 cmax = j;
  43.             }
  44.             if (A[i][j]<min) {
  45.                 min = A[i][j];
  46.                 lmin = i;
  47.                 cmin = min;
  48.             };
  49.         };
  50.     A[lmax][cmax]^=A[lmin][cmin]^=A[lmax][cmax]^=A[lmin][cmin];
  51.     print_matrix(A,n,m);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement