#include <iostream>
#include <random>
#include <ctime>
#include <iomanip>
#include <algorithm>
using namespace std;
class RNG {
private:
random_device rd;
default_random_engine re;
public:
RNG() { re.seed(this->rd()); }
double randreal() {
return uniform_real_distribution<>{-1, 2}(this->re);
}
};
int main() {
int k = 0;
double nc, nr;
cout << "Please, enter number of rows: ";
cin >> nr;
if (!cin || nr < 0) {
cout << "Error";
return 0;
}
cout << "Please, enter number of columns: ";
cin >> nc;
if (!cin || nc < 0) {
cout << "Error";
return 0;
}
cout << endl;
double** array = new double* [nr];
for (int i = 0; i < nr; i++) {
array[i] = new double[nc];
for (int j = 0; j < nc; j++) {
RNG gen{};
array[i][j] = gen.randreal();
cout << array[i][j] << " ";
}
cout << endl;
}
//вот тут нужно сделать вывод (кол-во столбцов)
}
C/C++
Подсчитайте количество столбцов массива, которые не содержат отрицательных значений.
#include <iostream>
#include <random>
#include <ctime>
#include <iomanip>
#include <algorithm>
using namespace std;
class RNG {
private:
random_device rd;
default_random_engine re;
public:
RNG() { re.seed(this->rd()); }
double randreal() {
return uniform_real_distribution<> { -1, 2 } (this->re);
}
} ;
int main() {
int k = 0;
int nc, nr;
cout << "Please, enter number of rows: ";
cin >> nr;
if (!cin || nr < 0) {
cout << "Error";
return 0;
}
cout << "Please, enter number of columns: ";
cin >> nc;
if (!cin || nc < 0) {
cout << "Error";
return 0;
}
cout << endl;
double** array = new double* [nr];
for (int i = 0; i < nr; i++) {
array[i] = new double[nc];
for (int j = 0; j < nc; j++) {
RNG gen { } ;
array[i][j] = gen.randreal();
cout << array[i][j] << "\t";
}
cout << endl;
}
//вот тут нужно сделать вывод (кол-во столбцов)
int count = 0;
for (int i = 0; i < nc; i++) {
int nonminus = 1;
for (int j = 0; j < nr; j++) {
if(array[j][i] < 0.0)
{
nonminus = 0;
break;
}
}
if(nonminus) count++;
}
cout << endl << count << endl;
}
#include <random>
#include <ctime>
#include <iomanip>
#include <algorithm>
using namespace std;
class RNG {
private:
random_device rd;
default_random_engine re;
public:
RNG() { re.seed(this->rd()); }
double randreal() {
return uniform_real_distribution<> { -1, 2 } (this->re);
}
} ;
int main() {
int k = 0;
int nc, nr;
cout << "Please, enter number of rows: ";
cin >> nr;
if (!cin || nr < 0) {
cout << "Error";
return 0;
}
cout << "Please, enter number of columns: ";
cin >> nc;
if (!cin || nc < 0) {
cout << "Error";
return 0;
}
cout << endl;
double** array = new double* [nr];
for (int i = 0; i < nr; i++) {
array[i] = new double[nc];
for (int j = 0; j < nc; j++) {
RNG gen { } ;
array[i][j] = gen.randreal();
cout << array[i][j] << "\t";
}
cout << endl;
}
//вот тут нужно сделать вывод (кол-во столбцов)
int count = 0;
for (int i = 0; i < nc; i++) {
int nonminus = 1;
for (int j = 0; j < nr; j++) {
if(array[j][i] < 0.0)
{
nonminus = 0;
break;
}
}
if(nonminus) count++;
}
cout << endl << count << endl;
}
Николай Шанаурин
Обратите внимание, что nr и nc должны иметь тип int
Похожие вопросы
- 5) Найти среднее значение элементов построчно и по столбцам массива n*n случайных чисел. с++ пж помагите
- Заменить нулями элементы массива, которые расположены между первым минимальным и последним максимальным элементами масси
- Си. Подсчитать количество появлений максимального элемента матрицы
- Для массива а(к) найти наименьшее значение pазности между pядом стоящими эле-ментами.
- С++ | Надо отсортировать двухмерный массив N*M в порядке возрастания и спадания ПО КАЖДОМУ СТОЛБЦУ ОТДЕЛЬНО
- С++ создать массив из элементов каждый из которых равен среднеарефметическому четных элементов каждого столбца
- Двумерный динамический массив с неизвестны количеством столбиков или строк
- Напишите рекурсивную функцию, которая принимает двухмерный массив целых чисел и количество сдвигов и выполняет
- Как узнать количество символов в UTF8 массиве?(Си)
- Почему не меняется значения в массиве