Twenty students were asked to participate in a survey to rate their experience with a tutoring center on a scale of 1 to 5 (where 1 means awful and 5 means excellent). Write a program that stores the 20 responses entered by the user in an integer array and summarize the results by displaying the number of occurrences of each response (1 to 5). As part of the solution, write and call the function calculate() with the following prototype. n1 is the size of the array of the responses and n2 is the size of the array of frequency.
void calculate(int responses[], int n1, int frequency[], int
n2);
Example input/output #1:
Enter 20 responses: 1 4 5 3 5 3 5 2 4 5 2 4 5 5 3 4 5 3 3 1
Output:
Rating Frequency
1
2
2
2
3
5
4
4
5
7
Code:
#include <stdio.h>
void calculate(int responses[], int n1, int frequency[], int n2);
int main( void ) {
int frequency[ 5 ] = { 0 };
int responses[ 20] = { 1, 4, 5, 3, 5, 3, 5, 2, 4, 5, 2, 4, 5, 5, 3,
4, 5, 3, 3, 1 };
calculate(responses, 20, frequency, 5);
return 0;
}
void calculate(int responses[], int n1, int frequency[], int
n2){
int answer,rating;
for ( answer = 0; answer < n1; ++answer ){
frequency[ responses [ answer ] ]=frequency[ responses [ answer ]
]+1;
}
printf( "%s%17s ", "Rating", "Frequency" );
for ( rating = 1; rating <= n2; ++rating ){
printf( "%6d%17d ", rating, frequency[ rating ] );
}
}
Output:

Twenty students were asked to participate in a survey to rate their experience with a tutoring...