Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main(int argc, const char* argv[]) {
- srand(time(NULL));
- setlocale(LC_ALL, "rus");
- int m, n;
- cout << "Введите кол-во строк n: ";
- cin >> n;
- cout << "Введите кол-во столбцов m: ";
- cin >> m;
- int u = 0;
- cout << "1 - описывая двумерный массив как указатель на массив указателей\n2 - описывая двумерный массив как одномерный, с расчётом смещения элемента массива по линейной формуле\n";
- cin >> u;
- switch (u)
- {
- case 1:
- {
- int** ptrarray;
- ptrarray = new int* [n];
- for (int i_row = 0; i_row < n; i_row++) {
- ptrarray[i_row] = new int[m];
- }
- cout << "Введите массив:" << endl;
- for (int i_row = 0; i_row < n; i_row++) {
- for (int j_column = 0; j_column < m; j_column++) {
- cin >> ptrarray[i_row][j_column];
- }
- }
- for (int i_row = 0; i_row < n; i_row++) {
- for (int j_column = 0; j_column < m; j_column++)
- cout << setw(2) << ptrarray[i_row][j_column] << " ";
- cout << endl;
- }
- cout << endl;
- int maxstolb, maxstrok;
- int maxMult = 0;
- maxMult = 0;
- for (int j = 0; j < n; j++)
- {
- int tempM = 1;
- for (int i = 0; i < m; i++)
- {
- tempM *= ptrarray[i][j];
- }
- if (maxMult < tempM) { maxstolb = j; maxMult = tempM; }
- }
- cout << "Максимальное произведение в столбике " << maxstolb + 1 << " = " << maxMult << endl;
- for (int k = 0; k < n; k++)
- delete[]ptrarray[k];
- delete[]ptrarray;
- break;
- }
- case 2:
- {
- int** ptrarray = new int* [n];
- for (int i = 0; i < n; i++) {
- ptrarray[i] = new int[n];
- }
- cout << "Введите массив:" << endl;
- for (int i_row = 0; i_row < n; i_row++) {
- for (int j_column = 0; j_column < m; j_column++) {
- cin >> ptrarray[i_row][j_column];
- }
- }
- for (int i_row = 0; i_row < n; i_row++) {
- for (int j_column = 0; j_column < m; j_column++)
- cout << setw(2) << ptrarray[i_row][j_column] << " ";
- cout << endl;
- }
- cout << endl;
- int maxstolb, maxstrok;
- int maxMult = 0;
- maxMult = 0;
- for (int j = 0; j < n; j++)
- {
- int tempM = 1;
- for (int i = 0; i < m; i++)
- {
- tempM *= ptrarray[i][j];
- }
- if (maxMult < tempM) { maxstolb = j; maxMult = tempM; }
- }
- cout << "Максимальное произведение в столбике " << maxstolb + 1 << " = " << maxMult << endl;
- delete[]ptrarray;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement