Hands-On Example 2.2 Hands-On Example 2.2 Solve a Simpler Problem Find the sum of f the first 200 whole numbers. This T seems daunting, right? And it would take a while e! However, if you solve a simpler problem, you can create an algorithm to find the sum of any set of sequential numbers. n Instead of adding up all of the numbers—1 + 2 + 3 + 4 + … + 199 + 200—look at t a simple problem. 1 Find the sum of f the first six numbers. First look at a the six numbers: 1 + 2 + 3 + 4 + 5 + + 6 = 21 2 Look for a pattern, r as shown. The numbers can be b arranged in pairs to find simpler sums. There are three sums of 7, so multiply 3 × 7 = 21. Notice that 3 is half of 6, which is the total number of whole l numbers to add. 1 2 3 4 5 6 7 7 7 Goodheart-Willcox Publisher 3 The simple algorithm o is to add the first and last numbers n together and multiply by half of the total numbe er of numbers. 4 Find the simpler r sum: 1 + 6 = 7. 5 Find the numbe er of pairs: 6 ÷ 2 = 3. 6 Find the product: c 3 × 7 = 21. The sum of the first s si x numbers is 21. 7 Apply the algori it hm to the original problem. 8 The simpler sum m is: 1 + 200 = 201. 9 The number of pairs p are: 200 ÷ 2 = 100. 0 The product is: 100 × 201 = 20,100. The sum of f the first 200 numbers is 20,100. Try It! Suppose the total a number of numbers to add is o od d instead of even. How would that change the algorithm? m Try to solve a simpler problem m to find out how that affects the algorithm. Apply this s algorithm to find the sum of the e first 51 whole numbers. If that was too easy, try finding the s su m of the first 100 odd numbers. s Copyright Goodheart-Willcox Co., Inc. 30 Introduction to Computer Science: Coding