void findFrequency(double grades[MAX_STUDENTS]) { double unique_grade[24]; int maxcount = 0; int i; int j = 0; printf("Grade: Frequency:\n"); for(i = 34; i > 0; i--) {//find unique grades int count = 0; for(j = 0; j < 34; j++){//find frequency if (grades[j] == grades[i]) count++; } if (count > maxcount) {//find mode maxcount = grade[i]; } if (grades[i] == grades[i-1]) { continue; } else unique_grade[i] = grades[i]; printf("%2.2f\t %i\n",unique_grade[i],count+1); } printf("%2.2f\n", "The mode is ", maxcount); }

# Finding unique grades, frequency, and mode in C

Page 1 of 1## 2 Replies - 1062 Views - Last Post: 20 March 2013 - 09:40 PM

### #1

# Finding unique grades, frequency, and mode in C

Posted 20 March 2013 - 07:00 PM

Hello, I am working on a C function that requires me to find the unique grades of an array of student grades, the frequency that grade appears, and the mode. I am having trouble with all three of these aspects to a degree. My unique_grades array repeats two separate numbers, and the frequency is not printing accurately. What can I do to fix these issues?

##
**Replies To:** Finding unique grades, frequency, and mode in C

### #2

## Re: Finding unique grades, frequency, and mode in C

Posted 20 March 2013 - 09:16 PM

First you appear to be accessing your arrays out of bounds. You declared your unique_array with a size of 24 yet in your loops you try to assign a value to element 34 in some cases.

How is MAX_STUDENTS defined?

What is the significance of the "magic numbers" 24 and 34 that you are using in your function?

Jim

How is MAX_STUDENTS defined?

What is the significance of the "magic numbers" 24 and 34 that you are using in your function?

Jim

### #3

## Re: Finding unique grades, frequency, and mode in C

Posted 20 March 2013 - 09:40 PM

Once you figure out what your "magic numbers" are supposed to mean, and you stop accessing elements outside the array bounds consider looking over your algorithm. Note that the grade with the highest frequency is the mode, and grades with a frequency of one is unique. How would you go about determining the answer if all you had was just had pen and paper rather than a computer? If you can explain in words the steps that you would take to solve the problem, then your at 75% to being able to describe an algorithm that you can implement on a computer.

Page 1 of 1