Calculating Perfect Squares A perfect square is the product of two equal whole numbers. For example, e 2 × 2 = 4. Four is the perfect square of 2. Sixty-four is the perfect square of 8 (8 × 8 = 64). There are several ways to find perfect squares. The first step is to understand the problem. In this example, the problem is to generate the first ten perfect squares. The second step is to devise a plan. One direct solution uses multiplication, as shown in Figure 2-4. This could be the steps, or algorithm, to solve the problem. Another way to approach devising a plan is to look for a pattern. A second algorithm can be found by looking for a pattern in the results. For example, subtract each perfect square from the one after it. See the pattern in the results, as shown in Figure 2-5. Notice that the numbers in color are odd numbers. This second algorithm uses odd numbers to generate the list of perfect squares. The next step is to carry out the plan. For the first algorithm, complete the direct multiplication, as shown in Figure 2-4. For the second algorithm, add the odd number to the previous total, as shown in Figure 2-6. The final step is to evaluate the success of the plan. Was the plan successful? Yes, both plans accurately calculate perfect squares. Either solution can be used by a computer to generate the first ten perfect squares. Playing Guess My Number In the Guess My Number game, one player thinks of a number and the other player tries to guess it. The first step is to understand the problem. In this example, the problem is to play the Guess My Number game. Plan: Plan: Multiply to find Multiply to find perfect squares perfect squares 1 × 1 = 1 2 × 2 = 4 3 × 3 = 9 4 × 4 = 16 5 × 5 = 25 6 × 6 = 36 7 × 7 = 49 8 × 8 = 64 9 × 9 = 81 Goodheart-Willcox Publisher Figure 2-4. Generating perfect squares by multiplying. Perfect Squares Perfect Squares Difference Between Perfect Difference Between Perfect Squares Squares 0 × 0 = 0 1 × 1 = 1 1 0 = 1 2 × 2 = 4 4 1 = 3 3 × 3 = 9 9 4 = 5 4 × 4 = 16 16 9 = 7 5 × 5 = 25 25 16 = 9 6 × 6 = 36 36 25 = 11 7 × 7 = 49 49 36 = 13 8 × 8 = 64 64 49 = 15 9 × 9 = 81 81 64 = 17 10 × 10 = 100 100 81 = 19 Goodheart-Willcox Publisher Figure 2-5. Finding a pattern by subtracting perfect squares Plan: Plan: Add odd numbers to previous Add odd numbers to previous total to find perfect squares total to find perfect squares 0 + 1 = 1 1 + 3 = 4 4 + 5 = 9 9 + 7 = 16 16 + 9 = 25 25 + 11 = 36 36 + 13 = 49 49 + 15 = 64 64 + 17 = 81 81 + 19 = 100 Goodheart-Willcox Publisher Figure 2-6. Generating perfect squares by adding odd numbers. Copyright Goodheart-Willcox Co., Inc. 28 Introduction to Computer Science: Coding
Previous Page Next Page