#include <stdio.h>
#define NP 10 /* number of people */
#define NS 4 /* number of sports */
int main(void) {
char result, survey[NP], most;
int i, pop, freq[NS] = { 0 };
const char *sports[NS] = {
"athletes", "swimming", "football", "badminton"
};
for (i = 0; i < NS; i++)
printf("%c: %s%s", 'A' + i, sports[i], (i + 1 < NS) ? "; " : "\n");
for (i = 0; i < NP; i++) {
printf("Person %d: ", i + 1);
scanf(" %c", &result);
survey[i] = result;
if ( !(result >= 'A' && result <= 'D') )
return 1;
freq[result - 'A']++;
if (i == 0)
most = result, pop = 1;
else if (freq[result - 'A'] > pop)
most = result, pop = freq[result - 'A'];
}
printf("The most popular sport (one of) is %c: %s (%d)\n", most,
sports[most - 'A'], pop);
for (i = 0; i < NP; i++)
if (survey[i] == most)
printf("Person %d\n", i + 1);
return 0;
}
/*
A: athletes; B: swimming; C: football; D: badminton
Person 1: A
Person 2: B
Person 3: C
Person 4: D
Person 5: C
Person 6: D
Person 7: A
Person 8: B
Person 9: D
Person 10: B
The most popular sport (one of) is D: badminton (3)
Person 4
Person 6
Person 9
*/
Comments
Leave a comment