operands (modulo)
TRANSCRIPT
![Page 1: Operands (Modulo)](https://reader037.vdocuments.us/reader037/viewer/2022083118/5877da2b1a28abaa6c8b5ff7/html5/thumbnails/1.jpg)
9% 4 is 1cout yield to display modulu1:
the following statement a string and a value, to cout:
17 % 3 is 2 (the remainder when 17 is divided by 3 is 2)
![Page 2: Operands (Modulo)](https://reader037.vdocuments.us/reader037/viewer/2022083118/5877da2b1a28abaa6c8b5ff7/html5/thumbnails/2.jpg)
14 % 2 is 0 (the remainder when 14 is divided by 2 is 0)
Integer Division
The division of two integer values can produce rather strange results for the unwary. For example, the expression 15/2 yields the integer result 7.
![Page 3: Operands (Modulo)](https://reader037.vdocuments.us/reader037/viewer/2022083118/5877da2b1a28abaa6c8b5ff7/html5/thumbnails/3.jpg)
Because integers can’t contain a fractional part, the value 7.5 can’t be obtained. The fractional part resulting when two integers are divided—the remainder—is always dropped (truncated).
Therefore 9/4 is 2.And 20/3 is 6.
![Page 4: Operands (Modulo)](https://reader037.vdocuments.us/reader037/viewer/2022083118/5877da2b1a28abaa6c8b5ff7/html5/thumbnails/4.jpg)
You need to retain the remainder of an integer division.
C++ provides the modulus operator (also referred to as the “remainder operator”),
This operator captures the remainder when an integer is divided by an integer; using a non-integer value with the modulus operator results in a compiler error.