#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int rows, cols;
cout << "Rows: ";
cin >> rows;
cout << "Cols: ";
cin >> cols;
cout << endl;
int** arr = new int* [rows];
for (int i = 0; i < rows; i++)
arr[i] = new int[cols];
}
for (int j = 0; j < cols; j++)
arr[i][j] = rand() % 100;
cout.width(3);
cout << arr[i][j];
for (int k = cols - 1; k >= 0; k--)
if (arr[i][k - 1] > arr[i][k])
int temp = arr[i][k - 1];
arr[i][k - 1] = arr[i][k];
arr[i][k] = temp;
delete[] arr[i];
delete[] arr;
Объяснение:
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
int rows, cols;
cout << "Rows: ";
cin >> rows;
cout << "Cols: ";
cin >> cols;
cout << endl;
int** arr = new int* [rows];
for (int i = 0; i < rows; i++)
{
arr[i] = new int[cols];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
arr[i][j] = rand() % 100;
cout.width(3);
cout << arr[i][j];
}
cout << endl;
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
for (int k = cols - 1; k >= 0; k--)
{
if (arr[i][k - 1] > arr[i][k])
{
int temp = arr[i][k - 1];
arr[i][k - 1] = arr[i][k];
arr[i][k] = temp;
}
}
}
}
cout << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
cout.width(3);
cout << arr[i][j];
}
cout << endl;
}
for (int i = 0; i < rows; i++)
{
delete[] arr[i];
}
delete[] arr;
}
Объяснение: