Can someone help me why the output is 12 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
20th Aug 2017, 4:14 AM
Pickle_Rick()
Pickle_Rick() - avatar
9 Answers
+ 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
20th Aug 2017, 4:19 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
20th Aug 2017, 4:28 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 2
got it now, change code & added comments to help me
20th Aug 2017, 5:14 AM
Pickle_Rick()
Pickle_Rick() - avatar
+ 1
thank you GAWEN
20th Aug 2017, 4:32 AM
Pickle_Rick()
Pickle_Rick() - avatar
+ 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
20th Aug 2017, 4:37 AM
sayan chandra
sayan chandra - avatar
+ 1
thank you sayan
20th Aug 2017, 4:45 AM
Pickle_Rick()
Pickle_Rick() - avatar
+ 1
I'm a kid and I understand what there saying so you can to
29th Aug 2017, 12:24 AM
HAZ GAMING
HAZ GAMING - avatar
+ 1
okay lvl two with one code
29th Aug 2017, 1:10 AM
Pickle_Rick()
Pickle_Rick() - avatar
0
I get b now = 3, but where is the 4 value come from, 3 * 4
20th Aug 2017, 4:28 AM
Pickle_Rick()
Pickle_Rick() - avatar