Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<iomanip>
- #include<ctime>
- using namespace std;
- void main()
- {
- srand(time(NULL));
- const int n = 5;
- int mas[n][n];
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- mas[i][j] = rand() % 9 +1;
- }
- cout << "Source array:" << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- cout << setw(4) << mas[i][j];
- cout << endl;
- }
- for (int i = 0; i<n/2; i++)
- for (int j = 0; j < n/2; j++)
- {
- if(n==n%2)swap(mas[i][j],mas[n / 2 + i][n / 2 + j]);
- else {
- swap(mas[i][j], mas[n - 1 - i][n - 1 - j]);
- //int tmp = mas[i][i];mas[i][i] = mas[n - 1 - i][n - 1 - i];mas[n - 1 - i][n - 1 - i] = tmp;
- }
- }
- cout << "Result array:" << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- cout << setw(4) << mas[i][j];
- cout << endl;
- }
- system("pause");
- }
Add Comment
Please, Sign In to add comment