В С++ будь ласка, завтра потрібно здати

Записати елементи прямокутної матриці в одновимірний масив в порядку
проходження стовпців.
Ответ
0/5 (0 оценок)
1
Hn94 3 года назад
Светило науки - 72 ответа - 0 раз оказано помощи

Объяснение:

#include <iostream>

#include <ctime>

#include <vector>

using namespace std;

int main()

{

srand(time(NULL));

int rows, cols;

cin >> rows >> cols;

cout << endl;

int** arr = new int*[rows];

vector <int> result;

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 < cols; i++)

{

for (int j = 0; j < rows; j++)

{

result.push_back(arr[j][i]);

}

}

cout << endl;

for (const auto& element : result)

{

cout << element << " ";

}

for (int i = 0; i < rows; i++)

{

delete[] arr[i];

}

delete[] arr;

}