0

Find what is the most occurred number on the given numbers

example: 1 2 3 2 5 The most occurred number is 2

4th Dec 2017, 6:13 PM
GODOF7
GODOF7 - avatar
8 Answers
+ 3
@GODOF7 I have posted a solution on a copy of this thread. Have you seen that?
5th Dec 2017, 9:17 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
#include<iostream> #include<algorithm> #include<iterator> using namespace std; int main() { int arr[5]; for(int &i:arr) cin>>i; int maxe=0, maxctr=0; for(int i : arr) { int c = count(begin(arr),end(arr),i); if(c > maxctr) { maxe = i; maxctr = c; } } cout<<maxe<<" is the most frequent " <<"element. \nIt occurred "<<maxctr <<" times."<<endl; }
5th Dec 2017, 9:18 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
4th Dec 2017, 6:32 PM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
0
thank you very much
4th Dec 2017, 7:09 PM
GODOF7
GODOF7 - avatar
0
it doesnt work yho, why?
5th Dec 2017, 3:20 AM
GODOF7
GODOF7 - avatar
0
if I change it to 5 is it gonna make a difference?
5th Dec 2017, 3:47 AM
GODOF7
GODOF7 - avatar
0
chnage the a[20] to a[5]
5th Dec 2017, 3:53 AM
GODOF7
GODOF7 - avatar
0
the result is always zero
5th Dec 2017, 3:53 AM
GODOF7
GODOF7 - avatar