+ 1
Why this code take 2 in output .....if condition is true only when i=1,3 on 2 condition is false why print 2
2 Answers
+ 4
This is is because the variable a is 6. It should be 2, if you want to print only even numbers.
All the three cases are true because 1,2,3 are divisible by 6.
+ 4
6 is divisible by 1,2,3 therefore condition a%i==0 is true. (6%2 == 0 is true)
Here `a` is 6 and `i` takes values in range 1 to 3 (inclusive)