+ 2

[CLOSED] What happens if the dividend is smaller than the divisor with modulus operator?

I've seem this case a few times and I don't know how to solve it... I can't tell what it outputs!! Examples: 1) 2 % 3 2) Int x = 3; x += x % 4; cout << x; Thank you!

22nd Jun 2019, 11:56 PM
UrBoyO
UrBoyO - avatar
3 Answers
+ 8
1. 2 % 3 == 2. 2. 3 % 4 == 3. In general, for n<m natural numbers we have n % m == n.
23rd Jun 2019, 12:10 AM
Diego
Diego - avatar
+ 3
@Diego Thank you!! This helps a lot! 😃
23rd Jun 2019, 1:43 AM
UrBoyO
UrBoyO - avatar
0
It returns the dividend value as the output
7th Aug 2019, 2:13 PM
Nithish Nithish
Nithish Nithish - avatar