Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // Fig. 6.7: fig06.07.c
  2. // Analyzing a student poll.
  3. #include <stdio.h>
  4. #define RESPONSES_SIZE 40
  5. #define FREQUENCY_SIZE 11
  6.  
  7.  
  8. int main(void)
  9. {
  10. int answer;
  11.  
  12. int rating;
  13.  
  14. int frequency[FREQUENCY_SIZE] = { 0 };
  15.  
  16. int responses[RESPONSES_SIZE] = { 1,2,6,4,8,5,9,7,8,10,1,6,3,8,6,10,3,8,2,7,6,5,7,6,8,6,7,5,6,6,5,6,7,5,6,4,8,6,8,10 };
  17.  
  18. for (size_t answer = 0; answer < RESPONSES_SIZE; ++answer)
  19. ++frequency[responses[answer]];
  20.  
  21. printf("%s%17s\n", "Rating", "Frequency");
  22.  
  23. for (rating = 1; rating < FREQUENCY_SIZE; rating++)
  24. printf("%6d%17d\n", rating, frequency[rating]);
  25.  
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement