Quick actions

cmd+k|ctrl+k

Navigation

Languages

lab7_948

Snippet info

Language

Cpp

Visibility

public

Author

maloy-

Created

2018-12-11T21:46:31Z

Updated

2018-12-11T21:46:31Z

#include <iostream>
using namespace std;

int main() {
    const int n = 5 ; 
    int a[n][n] ; 
    for (size_t i = 0 ; i < n ; i++){
        for (size_t j = 0 ; j < n ; j++){
            a[i][j] = rand() % 10 ; 
            cout << a[i][j] << "  ";
        }
        cout << endl ; 
    }
    
    int max = - 10 , x , y ; 
    
    for (size_t i = 0 ; i < n ; i++){
        for (size_t j = 0 ; j < n ; j++){
            if (( i == j ) or (i+j==n-1)){
                if ( a[i][j] > max ){
                    max = a[i][j] ; 
                    x = i + 1 ; 
                    y = j + 1 ; 
                }
            }
        } 
    }
    cout << max << "  " << x << " " << y << endl ; 
    int p ; 
     p = a[n/2][n/2] ; 
     a[n/2][n/2] = a[x-1][y-1] ; 
      a[x-1][y-1] = p ; 
    
    
    
    for (size_t i = 0 ; i < n ; i++){
        for (size_t j = 0 ; j < n ; j++){
            cout << a[i][j] << "  ";
        }
        cout << endl ; 
    }
      
    
    return 0;
}
INFO