Need a help . Problem facing on output and came it wrong. Explain what's output? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Need a help . Problem facing on output and came it wrong. Explain what's output?

int count = 0; int i; for(i= 0; i <=10; i++) { if (i%2==0) count++; }; printf("%d",count);

13th Sep 2020, 12:48 PM
Suparna Podder
Suparna Podder - avatar
2 Respostas
+ 3
It won't give any errors or warnings your code will give Output 6 You used loop which start from 0 to 10 total how many times loop will work 11 but in inner part you used if condition if(i%2==0) then count++ this will work if number is divisible by 2 and between 0 to 11 there are 6 numbers and count will increase total six times so so Output will be 6 . Firstly count is 0 it will increase if Number is divisible by 2 . First number 0%2==0 which is true so count will increase so next number will be 2 Which is divisible by 2 (2%2==0) condition true so count will increase again . Total 6 times count will increase . ............ Thankyou..........
13th Sep 2020, 1:06 PM
A S Raghuvanshi
A S Raghuvanshi - avatar