+ 2

Difference between '/' and '%' operators??

23rd Mar 2017, 4:29 PM
Rajan Sharma
5 Réponses
+ 4
/ is used to get quotient between division e.g. 5/2=2(exact2.5but not displays) % is used to get remainder e.g. 14%3=2(14/3=4 and remain 2)
23rd Mar 2017, 4:37 PM
Animesh
Animesh - avatar
+ 2
/ divides and returns that answer. Example- 10/2=5 % divides and returns the remainder Example- 13%2=1 because 13 divided by 2 is 6 with a remainder of 1.
24th Mar 2017, 2:19 AM
sarah
+ 2
Try dividing 26 by 6 (without decimals). You know that 24/6=4. But there's still 2 remaining that cannot be divided by 6. (At least without getting decimals) 2 is the modulus
27th Mar 2017, 7:45 AM
Winter
Winter - avatar
+ 1
To fill in on @animesh answer. if you want to display 2.5 you have to type it like this a = 5 b = 2 c = (decimal) a / b
23rd Mar 2017, 4:42 PM
Dextozz
Dextozz - avatar
+ 1
% operator return remainder.Example 6% 3=0 and 1 % 2 =1. / operator return quotient. Example 6 % 3=2 and 1 / 2=0 and 7 / 3=2.
22nd Jan 2018, 2:32 PM
Blacked False Positive
Blacked False Positive - avatar