Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int arr[9]={1,1,5,2,4,5,5,3,5};
- int main()
- {
- int sz=9;
- int mx=-1111111;
- vector<int>loc;
- int cnt=0;
- for(int i=0; i<sz; i++)
- {
- if(arr[i]<mx)
- continue;
- if(arr[i]==mx)
- {
- loc.push_back(i);
- cnt++;
- }
- else
- {
- mx=arr[i];
- cnt=1;
- loc.clear();
- loc.push_back(i);
- }
- }
- cout<<"maximum = "<<mx<<endl;
- cout<<"Count = "<<cnt<<endl;
- cout<<"locations of occurance: ";
- for(int i=0; i<loc.size(); i++)
- {
- cout<<loc[i]<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement