#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand((int)time(0));
int M, N;
cout << "M="; cin >> M;
do
cout << "N="; cin >> N;
if (N%2!=0) cout << "N - even. Repeat please...\n";
}
while (N%2!=0);
double **a = new double*[M];
for (int i = 0; i < M; i++)
a[i]=new double[N];
for (int j = 0; j < N; j++)
a[i][j]=rand()%9 + 1;
cout << a[i][j] << " ";
cout << "\n";
for (int j = 0; j < N/2; j++)
swap (a[i][j],a[i][j+N/2]);
cout <<"\n";
delete[]a[i];
delete[]a;
system("pause");
return 0;
Объяснение:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand((int)time(0));
int M, N;
cout << "M="; cin >> M;
do
{
cout << "N="; cin >> N;
if (N%2!=0) cout << "N - even. Repeat please...\n";
}
while (N%2!=0);
double **a = new double*[M];
for (int i = 0; i < M; i++)
a[i]=new double[N];
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
a[i][j]=rand()%9 + 1;
cout << a[i][j] << " ";
}
cout << "\n";
}
cout << "\n";
for (int i = 0; i < M; i++)
for (int j = 0; j < N/2; j++)
swap (a[i][j],a[i][j+N/2]);
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
cout << a[i][j] << " ";
cout <<"\n";
}
for (int i = 0; i < M; i++)
delete[]a[i];
delete[]a;
system("pause");
return 0;
}
Объяснение: