#include <iostream>
#include <cstdlib> // For rand() and srand()
#include <ctime> // For time()
int main() {
const int SIZE = 10;
int arr[SIZE];
// Seed the random number generator
std::srand(std::time(0));
// Fill the array with random numbers in the interval [-10, 10]
for (int i = 0; i < SIZE; ++i) {
arr[i] = std::rand() % 21 - 10; // Generates numbers from 0 to 20, then shifts to -10 to 10
}
// Display the array
std::cout << "Array elements: ";
for (int i = 0; i < SIZE; ++i) {
std::cout << arr[i] << " ";
}
std::cout << std::endl;
// Find the maximum and minimum elements and their indices
int maxElement = arr[0];
int minElement = arr[0];
int maxIndex = 0;
int minIndex = 0;
for (int i = 1; i < SIZE; ++i) {
if (arr[i] > maxElement) {
maxElement = arr[i];
maxIndex = i;
}
if (arr[i] < minElement) {
minElement = arr[i];
minIndex = i;
}
}
// Display the results
std::cout << "Maximum element: " << maxElement << " at index " << maxIndex << std::endl;
std::cout << "Minimum element: " << minElement << " at index " << minIndex << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4gIC8vIEZvciByYW5kKCkgYW5kIHNyYW5kKCkKI2luY2x1ZGUgPGN0aW1lPiAgICAvLyBGb3IgdGltZSgpCgppbnQgbWFpbigpIHsKICAgIGNvbnN0IGludCBTSVpFID0gMTA7CiAgICBpbnQgYXJyW1NJWkVdOwogICAgCiAgICAvLyBTZWVkIHRoZSByYW5kb20gbnVtYmVyIGdlbmVyYXRvcgogICAgc3RkOjpzcmFuZChzdGQ6OnRpbWUoMCkpOwoKICAgIC8vIEZpbGwgdGhlIGFycmF5IHdpdGggcmFuZG9tIG51bWJlcnMgaW4gdGhlIGludGVydmFsIFstMTAsIDEwXQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBTSVpFOyArK2kpIHsKICAgICAgICBhcnJbaV0gPSBzdGQ6OnJhbmQoKSAlIDIxIC0gMTA7ICAvLyBHZW5lcmF0ZXMgbnVtYmVycyBmcm9tIDAgdG8gMjAsIHRoZW4gc2hpZnRz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