Please help me: you need to select all negative values from a given two-dimensional dynamic array and replace them with positive values, and vice versa.
I created the array randomly:
#include <iostream> #include <string> using std::cout; using std::cin; using std::endl; int m, n, i, j, l, i_cont; int main() { setlocale(0, ""); cout << "Введите количество строк n= "; cin >> n; cout << endl; cout << "Введите количество столбцов m= "; cin >> m; cout << endl; int *str = new int[n]; // Инициализация двумерного динамического массива int **a = new int*[n]; // n строк в массиве for (i = 0; i < n; i++) a[i] = new int[m]; // и m столбцов for (l = 0; l <= i_cont; l++) { for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { a[i][j] = 0.001 * rand(); if (a[i][j] < 10) cout << a[i][j] << " "; else cout << a[i][j] << " "; } cout << endl; } ??????????? } delete[] str; for (i = 0; i < n; i++) delete[] a[i]; system("pause"); }
rand()never returns negative values. What isint *str = new int[n];and why is it needed? What isi_contand why is it needed? Why is memoryanot freed? - AnTstrand why is it needed ??? Your program doesn’t use thisstr. What is it here for? - AnT