Nov 7, 2020 at 12:12am
How to fill an array int arr = [75] with numbers from 1 to 5 in any order and display the number of numbers greater than 2?
Last edited on Nov 7, 2020 at 12:22am
Nov 7, 2020 at 1:40am
Hello chebyrek,
What have you tried so far?
Do you want to fill the array with random numbers or numbers entered by a user?
Checking for numbers > 2 is just an if statement.
Show what you have tries so anyonw reading this will have a better idea to suggest what to do.
Andy
Nov 7, 2020 at 6:02pm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <random>
#include <iostream>
#include <algorithm>
#include <iterator>
int main()
{
const size_t a_size {75};
const int mino {1};
const int maxno {5};
const int greater {2};
int arr[a_size] {};
auto rand {std::mt19937 {std::random_device {}()}};
auto nums {std::uniform_int_distribution<int> {mino, maxno}};
for (int& a : arr)
a = nums(rand);
std::cout << "Number > " << greater << " is " << std::count_if(std::begin(arr), std::end(arr), [](int n) {return n > greater; }) << '\n';
}
|
Last edited on Nov 7, 2020 at 6:02pm