1 / 12

This presentation includes custom animations.

This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode.

inge
Download Presentation

This presentation includes custom animations.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode. If you have opened this lesson in a browser and see a bar similar to that below, click on the Slide Show icon A notice similar to the one below may appear warning that ActiveX or other scripts are disabled. Enable the controls for this website in order to see the animations.

  2. Modulo This slide show describes the modulo operation. Vocabulary: modulo operand Christine S. Wolfe Ohio University Lancaster 2008-Aug-01

  3. A bakery box holds exactly 12 donuts. We can only sell donuts by the full box. Leftover donuts can be eaten by the staff. If we bake 24 donuts, there are no leftovers. If we bake 25 donuts, there is 1 leftover. If we bake 14 donuts, there are 2 leftovers.

  4. A bakery box holds exactly 12 donuts. We can only sell donuts by the full box. Leftover donuts can be eaten by the staff. How many donuts can the staff eat if… Click anywhere to see the next answer … 50 donuts are baked? 2 … 73 donuts are baked? 1 … 23 donuts are baked? 11 … 66 donuts are baked? 6 … 15 donuts are baked? 3 … 36 donuts are baked? 0 … 126 donuts are baked? 6 … 10 donuts are baked? 10 … 79 donuts are baked? 7 … 0 donuts are baked? 0

  5. Each cabin holds 5 campers. If there aren't enough campers for a full cabin, the extra campers have to sleep in the infirmary. If 5 people are camping, they all stay in a cabin and no one sleeps in the infirmary. Christine Wolfe: Ohio University Lancaster

  6. Each cabin holds 5 campers. If there aren't enough campers for a full cabin, the extra campers have to sleep in the infirmary. If 11 people are camping, 10 stay in cabins and 1 sleeps in the infirmary.

  7. Each cabin holds 5 campers. If there aren't enough campers for a full cabin, the extra campers have to sleep in the infirmary. Assuming an unlimited number of cabins, how many people have to sleep in the infirmary if…. … 6 go camping? 1 … 10 go camping? 0 … 15 go camping? 0 … no one goes camping? 0 … 5001 go camping? 1 … 16 go camping? 1 … 24 go camping? 4 … 18 go camping? 3 … 59 go camping? 4 … 2 go camping? 2

  8. The operation of determining "leftovers" or "remainders" is called Either of the following symbols is used to represent the modulo operation: % or Mod (We will use % because that is the symbol used in C) modulo. The operation to learn how many donuts are leftover after 50 are baked and stored in boxes that can hold 12 donuts is written: 50 % 12 and is read, "fifty modulo twelve" The solution is written: 2 = 50 % 12 and is read, "Two is the result of fifty modulo twelve." If 13 donuts are baked, the solution is: 1 = 13 % 12 If 24 donuts are baked, the solution is: 0 = 24 % 12 If you don't know how many donuts will be baked, you can use a variable to represent the number of donuts. In that case, the solution is: NumberOfLeftovers = NumberOfDonuts % 12 In programming, the variable that holds the result or answer is ALWAYS written on the left of the assignment operator click tip

  9. The operation to learn how many campers have to sleep in the infirmary when 11 campers show up and each cabin can hold 5 campers is written: 11 % 5 and is read, "eleven modulo five" The solution is written: 1 = 11 % 5 and is read, "One is the result of eleven modulo five." If you don't know how many campers will arrive, you can use a variable to represent the number of campers. In that case, the solution is: NumberWhoSleepInInfirmary = NumberOfCampers % 5 If you don't know how many campers will arrive AND you don't know how many campers can fit in a cabin, you can use variables to represent these unknowns. NumberWhoSleepInInfirmary = NumberOfCampers % NumberCampersPerCabin

  10. 1 0 3 6 Notice that the variable names do not start with a digit and they don't include any spaces. click tip

  11. What is the result of the following modulo operations? 16 % 12 4 25 % 8 1 16 % 2 0 25 % -8 implementation specific 17 % 5 2 103 % 10 3 163 % 8 3 16 % 10 6 6 % 2 0 7 % 3 1 -17 % 5 implementation specific 7 % 4 3 14 % 12 2 44 % 9 8 10 % 15 10 44 % 0 Division by zero error 25 % 5 0

  12. Modulo is used to solve problems where it is necessary to know if one number can be evenly divided by another number. Example 1: All even numbers and only even numbers are evenly divisible by 2. If the result of MysteryNumber % 2 is zero, then MysteryNumber must be even. Example 2: How many reams of paper are needed if I want to produce x number of 1 page brochures? Suppose I want to produce 600 brochures. 600 pages / 500 pages per ream = 1.2 reams But my paper is only sold in full reams. If I round off to 1 ream, I won't have enough paper. If I always buy 1 extra ream, I may buy a ream that I will never use as in the case when I need exactly 1000 pages. The solution is to test the result of NumberOfPages % 500 If the result is 0, do not add the extra ream. If the result is greater than 0, then add another ream to the order.

More Related