fork download
  1. #include <stdio.h>
  2. int main ()
  3. {
  4. int ratingCounters[11], i, response;
  5.  
  6. for ( i = 1; i<= 10; ++i )
  7. ratingCounters[i] = 0;
  8.  
  9. printf ("Enter your responses\n");
  10.  
  11. for ( i = 1; i<= 20; ++i )
  12. {
  13. scanf ("%i", &response);
  14.  
  15. if ( response < 1 || response > 10 )
  16. printf ("Bad response: %i\n", response);
  17. else
  18. ++ratingCounters[response];
  19. }
  20.  
  21. printf ("\n\nRating Number of Responses\n");
  22. printf ("------ -------------------\n");
  23.  
  24. for ( i = 1; i <= 10; ++i )
  25. printf ("%4i%14i\n", i, ratingCounters[i]);
  26.  
  27. return (0);
  28.  
  29. }
Success #stdin #stdout 0.01s 5288KB
stdin
6
5
8
3
9
6
5
7
15
5
5
1
7
4
10
5
5
6
8
9
stdout
Enter your responses
Bad response: 15


Rating   Number of Responses
------ -------------------
   1             1
   2             0
   3             1
   4             1
   5             6
   6             3
   7             2
   8             2
   9             2
  10             1