Table Of Contents
Previous Section Next Section

Program 20: Simpler Than Expected

This program is supposed produce a list of the squares of the numbers from 1 to 10. It does produce a list of squares, but this is not what the programmer expected.

  1 /************************************************
  2  * Print out the square of the numbers          *
  3  * from 1 to 10                                 *
  4  ************************************************/
  5 #include <iostream>
  6
  7 int main()
  8 {
  9     int index; /* Index into the table */
 10
 11     for (index = 1; index <= 10; ++index);
 12         std::cout << index << " squared " <<
 13             (index * index) << '\n';
 14
 15     return (0);
 16 }

(Next Hint 193. Answer 34.)

Table Of Contents
Previous Section Next Section