I want to write a function that displays the frequency of occurrence of an element entered by the user in a stored array. The array always has the following elements: 4, 2, 7, 10, 9, 7, 6, 10, -8, 7, 9.
well i wrote this one but i have a problem with it ..
#include <iostream>
using namespace std;
void freq(const int []);
int main()
{
int var=0;
int array[]={4, 2, 7, 10, 9, 7, 6, 10, -8, 7, 9};
cout<<"your numbers."<<endl;
for(int i=0;i<11;i++)
cout<<array[i]<<" , ";
cout<<endl;
cout<<"enter a number : "
for(int x=0;x<11;x++)
cout<<freq(array)<<endl;
return 0;
}
void freq(const int array[])
{
int count=0;
int variable=0;
for(int k=0;k<11;k++){
for(int j=0;j<11;j++){
if(j!=k){
if(array[k]==array[j]){
variable=array[k];
count++;
}
}
}
}
cout<<"the number "<<variable<<" occurred "<<count<<" times in your array."<<endl;
cout<<"press any key to continue.";
}