C/C++

Информатика нужна программа

GO
Gheorghe Opris
88
#include <iostream>
#include <random>
#include <algorithm>
#include <iterator>
#include <iomanip>
using namespace std;
void func(int* box, int n) {
for (int i = 0; i < n; ++i)
if (0 == box[i] % 3 && 0 == box[i] % 5)
cout << box[i] << ' ';
}
int main() {
const auto n = 8U, m = 12U;
uniform_int_distribution<> uid(10, 99);
mt19937 gen{ random_device()() };
int a[n][m];
for (auto& r : a) generate(begin(r), end(r), [&] { return uid(gen); });
for (auto& r : a) {
copy(begin(r), end(r), ostream_iterator<int>(cout, " "));
cout.put('\n');
}
cout.put('\n');
for (auto& r : a) func(r, m);
cout.put('\n');
system("pause > nul");
}
Михаил Коваленко
Михаил Коваленко
81 535
Лучший ответ
Денис Давыдов Одно непонятно: зачем делить на 3 и 5 по отдельности, если 3 и 5 — простые числа???
Вариант, который преподу объяснить легче, если не особо шаришь
#include < iostream >

#include < ctime >

int main()
{
int n = 0;
int m = 0;

std::cout << "N: ";
std::cin >> n;

std::cout << "M: ";
std::cin >> m;

int **array = new int *[n];

for (int i = 0; i < n; ++i)
array[i] = new int[m];

srand(time(nullptr));

for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
array[i][j] = rand() % 50;

if (array[i][j] % 3 == 0 || array[i][j] % 5 == 0)
std::cout << array[i][j] << " ";
}
}
return 0;
}