Commentary below slide.
|
|
Slide 48 of 99
Notes:
Division of two integers results in only the integer result. The fractional part is ignored. Here are some examples.
3 / 1 is 3 3 / 2 is 1 3 / 3 is 1 3 / 4 is 0
There is a special operator called the remainder or modulus operator that returns the integer remaining in the division. The operator is written as %. For example, 3 divided by 1 is 3 with a remainder of 0. In this case, 3 / 1 is 3 and 3 % 1 is 0. Likewise, 3 divided by 2 is 1 with a remainder of 1; so, 3 /2 is 1 and 3 % 2 is 1. Here are some more examples.
3 / 1 is 3 3 % 1 is 0 3 / 2 is 1 3 % 2 is 1 3 / 3 is 1 3 % 3 is 0 3 / 4 is 0 3 % 4 is 3