title: Using arrays to summarize survey results
body: <p><strong>This example from How to program c book</strong></p>
  
  <p>Forty students were asked to rate the quality of the food in the
      student cafeteria on a scale of 1 to 10 (1 means awful and 10 means
      excellent). Place the 40 responses in an integer array and summarize
      the results of the poll.</p>
  
  <hr>
  
  <p>I am stuck in understanding the algorithm used in this example and could not understand it , kindly if you can simplify it.thanks in advance</p>
  
  <pre><code>// Analyzing a student poll.
  #include &lt;stdio.h&gt;
  #define RESPONSES_SIZE 40 // define array sizes
  #define FREQUENCY_SIZE 11
  int main( void ) {
  size_t answer; // counter to loop through 40 responses
  size_t rating; // counter to loop through frequencies 1-10
  // initialize frequency counters to 0
  int frequency[ FREQUENCY_SIZE ] = { 0 };
  // place the survey responses in the responses array
  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 };
  // for each answer, select value of an element of array responses
  // and use that value as subscript in array frequency to
  // determine element to increment
  for ( answer = 0; answer &lt; RESPONSES_SIZE; ++answer )
  {
      frequency[ responses [ answer ] ]=frequency[ responses [ answer ] ]+1;
  } // end for
  // display results
  printf( "%s%17s\n", "Rating", "Frequency" );
  // output the frequencies in a tabular format
  for ( rating = 1; rating &lt; FREQUENCY_SIZE; ++rating )
  {
      printf( "%6d%17d\n", rating, frequency[ rating ] );
  } // end for
  // end main
  return 0;
  }
  </code></pre>