samedi 31 janvier 2015

Find Occurrences in Array

I Have to find the occurrences of every element in array. So far My code is this



void Occurrences()
{
int numers[10],count = 0,i;
for(i =0;i<10;i++)
{
cout<<"Enter Number";
cin>>numers[i];
}
for( i = 0;i<10;i++)
{
for(int j = 0;j<10;j++)
{
if(numers[i] == numers[j])
{
count++;
}
}
cout<<numers[i]<<" is Occur "<<count<<" Time in Array"<<endl;
count = 0;

}



}
int main()
{
Occurrences();
}


Output is coming multiply same numbers i.e if I entered six 1 and 4 2's. Output is 1 is occur 6 time in array. 1 is occur 6 time in array. 1 is occur 6 time in array. 1 is occur 6 time in array. 1 is occur 6 time in array. 1 is occur 6 time in array. 2 is occur 4 time in array. 2 is occur 4 time in array. 2 is occur 4 time in array. 2 is occur 4 time in array. But I want output like this 1 is occur 6 time in array. 2 is occur 4 time in array. How do I do this?


Aucun commentaire:

Enregistrer un commentaire