0
Can anyone tell me how to calculate frequency of each array elements in c?
eg 12342628569 :- here frequency of 2 is 3
9 ответов
+ 1
Frequency of 2 is not 3, it is 3/ size of array == 3/11
double freq(int * array, unsigned size, int value){
double res = 0.;
if(array && size)
for(unsigned i = 0; i < size; ++i)
if(array[i] == value)
res += 1;
return size?res/size:res;
}
if you wanted to know the number of time the value appears in the array, change double to unsigned and change the return line by :
return res;
0
thanks for your attention
0
but you you have misunderstood the question
0
In which way ?
0
the question is we have to count how many times no appears in array
0
yes, I also answered this just in case after the code ^^
0
is this code is for every no in array?
0
Yes, just have to change the third parameter to calculate for another number