#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter n: ";
cin >> n;
if (n % 2 != 0) {
int** Arr;
Arr = new int* [n];
for (int i = 0; i < n; i++) Arr[i] = new int[n];
cout << "Matrix:" << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
cin >> Arr[i][j];
}
int i1 = 0, j1 = 0, temp, max = Arr[0][0];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i == j || j == n - i - 1) {
if (max < Arr[i][j]) {
max = Arr[i][j];
i1 = i;
j1 = j;
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i == n / 2 && j == n / 2) {
temp = Arr[i][j];
Arr[i][j] = Arr[i1][j1];
Arr[i1][j1] = temp;
}
cout << "\nMatrix:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
cout << Arr[i][j] << " ";
cout << endl;
}
for (int i = 0; i < n; i++) delete[] Arr[i];
delete[] Arr;
}
else {
cout << " n must be odd! " << endl;
}
getchar();
getchar();
return 0;
}
Перед публікацією, радимо ознайомиться з правилами!
Знайшли помилку?
Ви можете повідомити про це адміністрацію.
Виділіть текст і натисніть CTRL+Enter