230k views
5 votes
In statistics the mode of a set of values is the value that occurs most often. Write a program that determines how many pieces of pie most people eat in a year. Set up an integer array that can hold responses from 30 people. For each person, enter the number of pieces they say they eat in a year. Then write a function that finds the mode of these 30 values. This will be the number of pie slices eaten by the most people. The function that finds and returns the mode should accept two arguments, an array of integers, and a value indicating how many elements are in the array.

User Appeiron
by
3.6k points

1 Answer

5 votes

Answer:

see below

Step-by-step explanation:

The program of interest is the function "findMode[x, n]" in the attached. It is written the Wolfram Language of Mathematica.

The basic idea is that the data in the array is sorted. The sorted array is partitioned into sets of identical elements, and the number in each of those sets is counted. The maximum of those counts is the mode. The location of the maximum count corresponds to the location of the set having that count. We use that location information to pull out the mode value(s).

If there is more than one mode, all are reported.

__

An example data array is provided, along with the program output.

In statistics the mode of a set of values is the value that occurs most often. Write-example-1
User Willem Mulder
by
3.7k points