// new_delete_array2.cpp: определяет точку входа для консольного приложения.
#include <iostream>
#include <ctime>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main(int argc, char* argv[])
{
setlocale(LC_CTYPE,"Russian");
int n = 5;
srand(time(NULL)); // генерация случайных чисел
// динамическое создание двумерного массива вещественных чисел на десять элементов
float **ptrarray = new float* [5]; // две строки в массиве
for (int count = 0; count < 5; count++)
ptrarray[count] = new float [5]; // и пять столбцов
// заполнение массива
for (int count_row = 0; count_row < 5; count_row++)
for (int count_column = 0; count_column < 5; count_column++)
//заполнение массива случайными числами с масштабированием от 1 до 10
ptrarray[count_row][count_column] = (rand() % 10 + 1) / float((rand() % 10 + 1));
// вывод массива
cout <<"Исходный массив"<<endl;
for (int count_row = 0; count_row < 5; count_row++)
{
for (int count_column = 0; count_column < 5; count_column++)
cout << setw(7) <<setprecision(5) << ptrarray[count_row][count_column] << " ";
cout << endl;
}
// удаление минммальной строки и столбца
int mini = 0, minj = 0;
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
if (ptrarray[i][j]<ptrarray[mini][minj])
{
mini = i;
minj = j;
}
for (int i=mini; i<n-1; i++)
for (int j=0; j<n; j++)
ptrarray[i][j] = ptrarray[i+1][j];
for (int j=minj; j<n-1; j++)
for (int i=0; i<n; i++)
ptrarray[i][j] = ptrarray[i][j+1];
--n;
// вывод нового массива
cout <<"Новый массив"<<endl;
for (int count_row = 0; count_row < 4; count_row++)
{
for (int count_column = 0; count_column < 4; count_column++)
cout << setw(7) <<setprecision(5) << ptrarray[count_row][count_column] << " ";
cout << endl;
}
// удаление двумерного динамического массива
for (int count = 0; count < 5; count++)
delete []ptrarray[count];
system("pause");
return 0;
}
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.