hello guys..i am trying this code for Finding frequencies of all elements of an array but its not working..help me
{
int no_ele;
cin>>no_ele;
cout<<no_ele;
float ele_array[no_ele];
for(int i=1;i<=no_ele;i++)
{
cin>>ele_array[i];
}
float f_array[no_ele]={0};
for(i = 1 ; i <= no_ele ; i++)
f_array[ele_array[i]]++;
for(i= 1; i <= no_ele ;i++)
cout<<i<<": "<<f_array[i]<<endl;
}
{
int no_ele;
cin>>no_ele;
cout<<no_ele;
float ele_array[no_ele];//can't do that! look up the delete[] and new[] operators on this site
// a normal array like this one must have a set number of elements
for(int i=1;i<=no_ele;i++){//start indexing at 0, in c++ arrays always start at 0, not one
//that means your for statment should be for(int i=0; i<no_ele; i++)
cin>>ele_array[i];
}
float f_array[no_ele]={0};//same as above, can't do this
for(i = 1 ; i <= no_ele ; i++)//same as above, index starts at 0
f_array[ele_array[i]]++; //you can not use a floating point number to index through an array
//e.g. can't access element 1.5
// also, what if ele_array is bigger then no_ele? you will get an error
for(i= 1; i <= no_ele ;i++)
cout<<i<<": "<<f_array[i]<<endl;
}