int cols;
int rows;
cout << "Введите размер столбцов ->" << endl;
cin >> cols;
cout << "Введите размер строк ->" << endl;
cin >> rows;
//выделение памяти для двумерного массива
int **ptrarray = new int*[cols];
for (int count = 0; count < cols; count++)
ptrarray[count] = new int[rows];
for (int count_row = 0; count_row < cols; count_row++)
for (int count_column = 0; count_column < rows; count_column++)
ptrarray[count_row][count_column] = rand() % 41 + (-20);
for (int count_row = 0; count_row < cols; count_row++)
{
for (int count_column = 0; count_column < rows; count_column++)
cout << setw(4) << setprecision(2) << ptrarray[count_row][count_column] << " ";
cout << endl;
}
// удаление двумерного динамического массива
for (int count = 0; count < cols; count++)
delete[] ptrarray[count];
delete[] ptrarray;
Объяснение:
Поделитесь своими знаниями, ответьте на вопрос:
Используя вс алгоритмы, нарисуйте:
Подредактируй ввод вывод.
или вот
#include<bits/stdc++.h>
using namespace std;
const int N = 1024+3; //size of "RAM"vector<pair<bool, int> > ram(N); //ram
int get_area(int n){ for (int i = 0; i < N-n-1 ; i ++) { if(ram[i].first == false) { int j; for (j = i; j < i+n ; j ++ ) if(ram[j].first == true) break; if (ram[j].first == true) { i = j; continue; } for(j = i ; j < i+n ; j ++) { ram[j].first = true; ram[j].second = i; } return i; } } return -1;
}
string del_area(int n){ int j = n; for(int i = n ; ram[j].second == ram[i].second && i < N-1; i ++) { ram[i].first = false; ram[i].second = 0; } return "Success! Area deleted!";}
int get_status(){ cout << endl << "Byte using of 1024 RAM:" << endl; for(int i = 0 ; i < N-2 ; i ++) { if(ram[i].first == false) cout << "-" << ' '; else cout << ram[i].second << ' '; }}
int main(){ ///code by Dmitry Kulazhenko (DmitryCpp) ///ram index begins at 0 ///give area of RAM, size n get_area enter n ///delete area, with start index n del_area enter n ///give status of using RAM get_status ///to quit exit string s; while( s != "exit" ) { cin >> s; if (s == "get_area") { int n; cin >> n; cout << get_area(n); cout << endl; } if (s == "del_area") { int n; cin >> n; cout << del_area(n); cout << endl; } if (s == "get_status") { cout << get_status(); cout << endl; } } return 0;}