Answer:
#include <iostream>
using namespace std;
int largestIndex(int list[], int listSize);
int main()
{
int alpha[10] = { 3, 6, 2, 6, 4, 1, 0, 5, 4, 2 };
cout << "The index of the last occurrence of the largest element in the array is " << largestIndex(alpha, 10) << endl;
return 0; }
int largestIndex(int list[], int listSize) {
int largestIndex = 0;
for (int counter = 1; counter < listSize; counter++)
if (list[counter] >= list[largestIndex])
largestIndex = counter;
return largestIndex;
}
Explanation:
The function keeps track of the index of the largest value and updates it when the same or a larger value is found.