AP® Computer Science Principles Crash Course by Jacqueline Corricelli

AP® Computer Science Principles Crash Course by Jacqueline Corricelli

Author:Jacqueline Corricelli
Language: eng
Format: epub
Publisher: Research & Education Association
Published: 2018-09-14T16:00:00+00:00


You cannot have 0 to the right of the MOD.

Example: 20 MOD 0 does not make sense since this would be like dividing by 0.

You can have 0 to the left of the MOD.

Example: 0 MOD 4 is 0 since 0 divided by any number that is not 0 is 0 with a remainder of 0.

Watch for division by 0 errors in MOD calculations — this can get a little confusing. 20 MOD 0 is not valid. 0 MOD 20 is 0. The 0 cannot be to the right of MOD.

iii.Modulus is often used in a program for the following purposes:

To determine if numbers are even or odd.

– If 2 is to the right of MOD, the result of this operation will tell you if the number to the left of MOD is even or odd.

Example 1: 7 MOD 2 is 1. This means 7 is odd.

Example 2: 8 MOD 2 is 0. This means 8 is even.

– General Rule:

If x MOD 2 is 1, x is ODD.

If x MOD 2 is 0, x is EVEN.

To convert between number systems.

– Suppose you want to convert 1600 hours (military time) to our normal AM/PM clock time. 1600 hours is 16:00. The “normal” clock time is a 12–hour system. Applying a modulus of 12 will do the trick!

16 MOD 12 is 4. 16:00 in military time is 4:00.

– If you research MODULUS online, you might see it referred to as “clock time” for this reason.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.