int main() { int a[24]; int max = 0, min = 0; for (int i = 0; i <= 24; ++i) { a[i] = uid(gen); cout << a[i] << " "; if (i == 0) { min = max = a[i]; } else { if (a[i] > max) { max = a[i]; } if (a[i] < min) { min = a[i]; } } } cout << " Result: " << max - min << endl; return 0; }
Answers & Comments
#include <ctime>
#include <random>
using namespace std;
mt19937 gen(time(0));
uniform_int_distribution<> uid(125, 200);
int main()
{
int a[24];
int max = 0, min = 0;
for (int i = 0; i <= 24; ++i) {
a[i] = uid(gen);
cout << a[i] << " ";
if (i == 0) {
min = max = a[i];
} else {
if (a[i] > max) {
max = a[i];
}
if (a[i] < min) {
min = a[i];
}
}
}
cout << " Result: " << max - min << endl;
return 0;
}