+ 1
Can someone help me why the output is 12
9 Réponses
+ 8
Loop runs for b values of 3 and 4. These values are multiples and stored in a.
1 * 3 = 3
3 * 4 = 12
final output : 12
+ 3
you are using (++b<5)where the value of b is 2 and a is 1
in first b is increment by 1 due to pre increment and become 3 so
a*=b become a=1*3=3 so now a become 3
then b is again increment by 1 and become 4 which is also satisfy the condition and then it goes to a
a*=b where a=3 b=4 so a*=b become 3*4=12
so final output shows a=12
+ 2
got it now, change code & added comments to help me
+ 1
thank you GAWEN
+ 1
a=1 , b=2
while ++b<5
... ( now b=3)
a*=b
... (now a= a*b= 1*3= 3)
2nd time while loop continues(b=3 and a=3 as of now)
while ++b<5
... b is 4 now
a*=b
... a=a*b=3*4=12 now
3 rd time while loop starting to continue
(b=4 and a= 12 as of now)
... while ++b<5
but ++b=5 which is not greater than 5
// so program breaks out from while loop
// last value of a was 12
//it shows 12
+ 1
thank you sayan
+ 1
I'm a kid and I understand what there saying so you can to
+ 1
okay lvl two with one code
0
I get b now = 3, but where is the 4 value come from, 3 * 4