+ 1

a=8, a/=3, puts 4%a =0?? Why

18th Nov 2016, 4:30 PM
ivan
ivan - avatar
9 Respostas
+ 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)
18th Nov 2016, 5:44 PM
Rebeka Asryan
Rebeka Asryan - avatar
+ 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.
21st Nov 2016, 3:44 AM
Rebeka Asryan
Rebeka Asryan - avatar
+ 3
a/=3 ---> a = 8/3 ---> (2.666...) ---> a is an integer ---> 2 4%a = 4%2 = 0
25th Nov 2016, 5:01 PM
John Coolway
John Coolway - avatar
+ 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.
26th Nov 2016, 2:09 AM
Daniel
Daniel - avatar
0
a/=3 means a=a/3 therefore a=2 that's y 4%2=0 (modulus of 2)
18th Nov 2016, 4:34 PM
Vishal Mahato
Vishal Mahato - avatar
0
a=8/3=2. 4%2=0. modulus is the remainder of 4/2.
18th Nov 2016, 5:03 PM
Junjie Gono
Junjie Gono - avatar
0
thank you
18th Nov 2016, 5:45 PM
ivan
ivan - avatar
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 ^
21st Nov 2016, 2:55 AM
joseph
joseph - avatar
0
0
19th Dec 2016, 5:06 PM
K.Naga Sai Manikanta