Answer:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n=0,a[1000],c=0,val=10,ma=INT_MIN;//n is for size c for count of maximum,ma to store maximum.
cout<<"Enter the values"<<endl;
cin>>val;//taking input..
while(val!=0)
{
a[n++]=val;
cin>>val;
}
for(int i=0;i<n;i++)//loop for finding the maximum in the array.
{
ma=max(a[i],ma);
}
for(int i=0;i<n;i++)//loop for counting the occurence of maximum.
{
if(a[i]==ma)
c++;
}
cout<<"The maximum value is "<<ma<<" The count of maximum value is "<<c<<endl;//printing the result..
return 0;
}
Output:-
Enter the values
5 4 7 8 5 8 4 5 6 2 1 5 3 8 8 8 8 0
The maximum value is 8 The count of maximum value is 6
Step-by-step explanation:
I have iterated over the array twice.First time to find the maximum and second time to find the occurrences of the maximum in the array. The value of ma is minimum number possible because if we assign it maximum value possible it will become the maximum.