+ 4
What is the work of % in c++
7 ответов
+ 38
Correction in nAutAxH AhmAd answer
He stated correctly but it's not
10 % 2 = 5
It is 10 % 2 = 0
( As 10 is divided by 2)
And
2 % 3 = 3 (incorrect)
2 % 3 = 2
( As 2 is not divided by 3 so remainder is 2)
+ 3
Vinesh Wadhwani🇮🇳 Thanks for correcting, didn't noticed about the typos.
+ 2
thank you guys....
+ 1
If two numbers are divided equally then remainder would be Zero.
If two numbers are divided unequally then the remainder would be non-zero value.
5 % 2 = 1
6 % 3 = 0
10 % 3 = 1
10 % 2 = 5
If the number on the left side of modulo operator is less than the number on the right of modulo operator, then the result will be the number on left side.
2 % 3 = 3
-5 % 10 = -5
0
please it not clear
0
simply put , the modulo operater gives you the remainder , its division but only considering the remainder of the division executed