+ 3
How to find a most recurring number in an array
let's say I have an array int[] arr=new arr{1,2,3,1,3,3,4,5,1,2,5,5,4,4,5,5,5}; most recurring number is 5? so how can we slove this?
2 Réponses
+ 6
sort the array. Then
int maxcount=0,var;
for(int I=0;I<size;)
{
int temp=ar[I];
int count=0;
while(ar[I]==temp)
{
count ++;
I++;
}
if(maxcount<count)
{
maxcount=count;
var=ar[i-1];
}
}
cout<<maxcount<<endl<<var;
+ 1
half problem solved but how can we count n find out which number is recurring using loops