array occurences

This is a discussion on array occurences within the C Programming forums, part of the General Programming Boards category; Hi guys, ive tried to implement an array to find out the occurence of a single number, im stuck because ...

array occurences

Hi guys, ive tried to implement an array to find out the occurence of a single number, im stuck because i dont know how to display the number and its frequency in the output. Ive searched the board but it only mentions using 2d arrays and stuff.
Thanks

You need to calculate the frequency of each value in the array? Then your algorithm isn't correct.

> values = values_array( numbers, SIZE );

Here you fill the array with values.

> calc_freq( numbers, values );

Here you want to calculate the frequency of each value in the array. When doing this in your function:

> ++A[i];

You change the value of the element in the array. So when comparing, you compare with a changed value, not with the original value in that element. I think that is not how it should be. Better would be to pass a second array to the function and store the frequencies in that array.