+ 1
a=8, a/=3, puts 4%a =0?? Why
9 Answers
+ 40
a/=3 means a=a/3.. so integer division 8/3= 2.. a becomes 2.. and the reminder after dividing 4 by 2 is 0, that's why 4%a=0 ( a=2 and 4%2=0)
+ 8
@joseph, it is not written that a is equal to 8 but also 8/3.. It is stated that at first a = 8, than a becomes a = a/3, that's why after the line a=a/3, a becomes 2.. we can use the value of a as we want, but we don't say that it us equal to two different numbers.. instead, we just change the value of a.
+ 3
a/=3 ---> a = 8/3 ---> (2.666...) ---> a is an integer ---> 2
4%a = 4%2 = 0
+ 1
When you divide an integer by another integer, all decimals are ignored.
Therefore a/=3 gives an integer of 2 and the rest (0.6667 ) is dropped.
4%2 gives the reminder after division. Therefore since 2 goes into 4 exactly twice, it will have a reminder 0.
0
a/=3 means a=a/3 therefore a=2
that's y 4%2=0 (modulus of 2)
0
a=8/3=2. 4%2=0. modulus is the remainder of 4/2.
0
thank you
0
in plain english is it not the same as saying a is equal to 8 but also a is equal to 8/3 ? how does that not confuse the program and why would one ever need ^
0
0