Thread: Finding the Mode of an integer array

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    3

    Question Finding the Mode of an integer array

    I want to write a function that will take an array of integers and determine the mode of those integers. Can anyone help out ?

    If someone could show me an example I would be forever grateful.

    Thanks a ton.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    void foo( int bar[], int arraysize )

    It's fairly simple. You'd be best served using two arugments, one to denote the size of the array you are passing.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Do a search on this board, there have been many discussions on this topic. One such is this one.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    3
    What I've set up is to prompt the "user" for the number of test subjects that were surveyed.

    I then dynamically create the array of integers with that many elements.

    I then prompt the user to input into the array the number of movies the test subjects watched.

    I then calculate the average, median, and the mode of the values entered.

    average(); works fine
    median(); works fine

    its the mode() that I'm just not getting.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    3
    Hey thanks alot guys, I really appreciate it.

    hk_mp5kpdw thanks for the link, I would never have thought about using vectors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. finding size of empty char array
    By darsunt in forum C Programming
    Replies: 12
    Last Post: 05-30-2006, 07:23 PM
  2. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  3. Finding the mode of an array
    By Shnakepup in forum C++ Programming
    Replies: 16
    Last Post: 05-16-2003, 10:01 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. mode of an array
    By Need Help in forum C Programming
    Replies: 15
    Last Post: 09-17-2001, 08:03 AM