How Modulus operator works?
Given two integers a
(dividend) and b
(divisor):
a % b
returns the remainder whena
is divided byb
.
Mathematically, we can express this as:
a=q⋅b+r
Where:
- a is the dividend (the number being divided).
- b is the divisor (the number dividing the dividend).
- q is the quotient (the result of the division).
- r is the remainder.
The modulus operator yields r, the remainder, when a is divided by b.
Modulus Operator in Programming
The modulus operator, often represented by the symbol ‘%'
, is a fundamental arithmetic operator used in programming languages to find the remainder of a division operation between two numbers. It returns the remainder of dividing the first operand by the second operand.
Table of Content
- What is the Modulus Operator?
- Basic Syntax of Modulus Operator
- How Modulus operator works?
- Properties of Modulus operator
- Example to show Modulus operator
- Modulus Operator in C
- Modulus Operator in C++
- Modulus Operator in Java
- Modulus Operator in Python
- Modulus Operator in C#
- Modulus Operator in Javascript
- Uses or Application of Modulus Operator
- Performance Considerations of Modulus Operator
Contact Us