0

Modulus operator %

somebody please explain how a % operator in c++ works suppose, int x = 6%4 ; how is value of x evaluated?

28th Nov 2016, 4:26 AM
shaheer shukur
shaheer shukur - avatar
3 Answers
+ 1
modulus is the remainder of the 2 numbers. when you divide 6 by 4, you'll get 1 remainder 2. so the answer of 6%4 is 2. 6/3 = 2 remainder 0 6%3 = 0 6/5 = 1 remainder 1 6%5 = 1 7/5 = 1 remainder 2 7%5 = 2
28th Nov 2016, 5:53 AM
Junjie Gono
Junjie Gono - avatar
+ 1
See my "% Modulus explained" code to understand in a way, you may have learnt at school https://code.sololearn.com/c2fRl6x893E7/?ref=app
31st Dec 2016, 12:42 PM
Vishal++
Vishal++ - avatar
0
the answer is the remainder of the equation not the normal answer
28th Nov 2016, 6:49 AM
Ian
Ian - avatar