Get the Frequency and the Indices of Maximum Number in an Array

23:34 0 Comments A+ a-

Problem:
Get the Frequency and the Indices of Maximum Number in an Array
Sample Run 1:
Enter 10 Numbers:
10 20 30 87 40 87 86 23 59 78

Total “2” occurrence(s) of the Maximum.
Found at index# 3 5
Solution:
# include <iostream>
using namespace std;
void inputArray(int array[], const int size)
{
cout << "Enter " << size << " Numbers: " << endl;
for (int i=0;i < size;i++)
{
cin >> array[i];
}
}
void getMaxIndex(int array[],int size)
{
int max=array[0];
int count=0;
int maxIndex[10];
for(int i=1;i<size;i++)
{
if(array[i]>max)
{
max=array[i];
}
}
for(int i=0;i<size;i++)
{
if(array[i]==max)
{
maxIndex[count]=i;
count++;
}
}
cout<<"Total "<<count<<" occurrence(s) of the Maximum"<<endl;
for(int j=0;j<count;j++)
{
cout<<maxIndex[j]<<" "<<endl;
}

}
int main()
{
const int size = 10;
int array[size];
inputArray(array, size);
getMaxIndex(array,size);

return 0;

}