#include <iostream>
#include <algorithm>
#include <iterator>
#include <random>
#include <array>
const size_t
N = 5,
M = 10;
int main()
{
std::random_device rnd;
std::default_random_engine generator(rnd());
std::uniform_int_distribution<int> dist(-10, 10);
std::array<int, M> arr[N];
std::for_each(arr, arr + N, [&dist, &generator](auto& var)
std::for_each(var.begin(), var.end(), [&dist, &generator](auto& var1)
var1 = dist(generator);
});
std::for_each(arr, arr + N, [](auto& var)
copy(var.begin(), var.end(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
size_t count = 0;
std::for_each(arr, arr + N, [&count](auto& var)
std::cout << count++ << " | " << std::count_if(var.begin(), var.end(), [](const auto& var) { return var > 0; }) << std::endl;
std::system("PAUSE >> void");
return 0;
}
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <algorithm>
#include <iterator>
#include <random>
#include <array>
const size_t
N = 5,
M = 10;
int main()
{
std::random_device rnd;
std::default_random_engine generator(rnd());
std::uniform_int_distribution<int> dist(-10, 10);
std::array<int, M> arr[N];
std::for_each(arr, arr + N, [&dist, &generator](auto& var)
{
std::for_each(var.begin(), var.end(), [&dist, &generator](auto& var1)
{
var1 = dist(generator);
});
});
std::for_each(arr, arr + N, [](auto& var)
{
copy(var.begin(), var.end(),
std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;
});
std::cout << std::endl;
size_t count = 0;
std::for_each(arr, arr + N, [&count](auto& var)
{
std::cout << count++ << " | " << std::count_if(var.begin(), var.end(), [](const auto& var) { return var > 0; }) << std::endl;
});
std::system("PAUSE >> void");
return 0;
}