Search code examples
cmode

Calculate all modes in c


Can you give me some hint on how to calculate if there are two or more modes in c?

I was able to create a program that will calculate for the mode, but if i have a dataset with multiple modes, like 5,3,1,2,3,4,6,4 my program only finds 3 as a mode, rather than both 3 and 4.


Solution

  • An approach might go something like this:

    1. Determine how many times each value appears, keep a list
    2. Determine the maximum number of times any value appears (by looking at your list)
    3. Find all values that appear the maximum number of times (by looking at your list)