Hands-On Example 2.3A Hands-On Example 2.3A Write an Algorithm g A computer uses s a series of steps in a program to o find the solution to a problem. Act like a computer and find the average number of days in a month in a nonleap year. Write an algorithm to solve th he problem. 1 Find the numbe er of days in each month: Month Month Number of Days Number of Days Month Month Number of Days Number of Days January 31 July 31 February 28 August 31 31 September 30 March 30 October 31 April 31 November 30 May 30 December 31 June 2 Add the number rs . The sum is 365. 3 Divide the sum by the number of months (12): 365 6 ÷ 12 = 30.41667 4 Round the answ we r to a whole number of days: 30 0 days. Try It! A leap year occurs u once every four years. In leap y ye ars, there is one extra day. February has 29 days instead o of 28. The extra day is needed to k ke ep the calendar in step with the actual rotation of Earth. In o on e year, Earth actually rotates a little less than 365 1/4 times. Write an algorithm to find the e average number of days per month n in a leap year. Carry Out the Plan With a plan in place, the next step is to carry it out. Find the number of days in each month. This list will contain 12 numbers. Next, add the numbers in the list. Divide the sum of the numbers by 12, which is the number of months. Finally, round the answer to a whole number of days. Review and Reflect The final step is to review and reflect on the plan. Consider if the plan found an acceptable solution. The algorithm described above accurately calculates the average number of days in each month in a nonleap year. Does the algorithm change if the year is a leap year? No, the algorithm does not change. The number of months stays the same, and the algorithm says to count the days in each month. However, a different result will be produced. Copyright Goodheart-Willcox Co., Inc. Chapter 2 Solving Problems 33