#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
// Seed the random number generator
srand(time(0));
// Declare an array of 10 integers
int arr[10];
// Fill the array with random numbers between -10 and 10
for (int i = 0; i < 10; i++) {
arr[i] = rand() % 21 - 10; // Generate random numbers in [-10, 10]
}
// Initialize variables to store the maximum and minimum values and their indices
int maxVal = arr[0];
int minVal = arr[0];
int maxIndex = 0;
int minIndex = 0;
// Find the maximum and minimum elements and their indices
for (int i = 1; i < 10; i++) {
if (arr[i] > maxVal) {
maxVal = arr[i];
maxIndex = i;
}
if (arr[i] < minVal) {
minVal = arr[i];
minIndex = i;
}
}
// Print the array elements
cout << "Array elements: ";
for (int i = 0; i < 10; i++) {
cout << arr[i] << " ";
}
cout << endl;
// Print the maximum and minimum elements and their indices
cout << "Maximum element: " << maxVal << " at index " << maxIndex << endl;
cout << "Minimum element: " << minVal << " at index " << minIndex << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGN0aW1lPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogIC8vIFNlZWQgdGhlIHJhbmRvbSBudW1iZXIgZ2VuZXJhdG9yCiAgc3JhbmQodGltZSgwKSk7CgogIC8vIERlY2xhcmUgYW4gYXJyYXkgb2YgMTAgaW50ZWdlcnMKICBpbnQgYXJyWzEwXTsKCiAgLy8gRmlsbCB0aGUgYXJyYXkgd2l0aCByYW5kb20gbnVtYmVycyBiZXR3ZWVuIC0xMCBhbmQgMTAKICBmb3IgKGludCBpID0gMDsgaSA8IDEwOyBpKyspIHsKICAgIGFycltpXSA9IHJhbmQoKSAlIDIxIC0gMTA7IC8vIEdlbmVyYXRlIHJhbmRvbSBudW1iZXJzIGluIFstMTAsIDEwXQogIH0KCiAgLy8gSW5pdGlhbGl6ZSB2YXJpYWJsZXMgdG8gc3RvcmUgdGhlIG1heGltdW0gYW5kIG1pbmltdW0gdmFs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