Find the max element along with it's index in c++
#include <iostream>
#include <climits>
int main() {
const int size = 5; // Replace with the actual size of your array
int arr[size] = {10, 5, 8, 15, 3}; // Replace with your array
int maxElement = INT_MIN;
int maxIndex = -1;
for (int i = 0; i < size; ++i) {
if (arr[i] > maxElement) {
maxElement = arr[i];
maxIndex = i;
}
}
std::cout << "Maximum element: " << maxElement << std::endl;
std::cout << "Index of maximum element: " << maxIndex << std::endl;
return 0;
}