+ 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

https://code.sololearn.com/cFnTCDHnmaXR/?ref=app

8th Oct 2020, 7:52 AM
Vikramjeet Singh
Vikramjeet Singh - avatar
2 ответов
+ 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.
8th Oct 2020, 8:00 AM
Steve Sajeev
Steve Sajeev - avatar
+ 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)
8th Oct 2020, 7:54 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar