What kind of math is happening in my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What kind of math is happening in my code?

I wrote a code and cont make sense of all its output. If you can understand it please inform me. https://code.sololearn.com/ct9cJCmbTrhw/?ref=app thankyou.

25th Jan 2018, 6:37 PM
emily gilespie
emily gilespie - avatar
3 Answers
+ 9
I've take a look, not found any problem in your code, remember while loop just stop repeat doing when the condition of it false. And for loop either. Your for loop run 2 times, in the second time of for loop it changes the value to 324 in the first while. And become 40 in the second while( in second while it have to run 3 time to satisfy the condition of while loop, that why we have 40.)
25th Jan 2018, 7:37 PM
Tran Huu Dang
Tran Huu Dang - avatar
+ 3
given*=6; is given=given*6; is given=6*6; is given=36; while(given<11) is false so loop exits given/=2; is given=given/2; is given=38/2; is given=18; while(given>40) is false so loop exits given*=3; is given=given*3; is given=18*3; is given=54; while(given<20) is false so loop exits for(int x=given;x<8;x++) increments x to 7 and continues given*=6; is given=given*6; is given=54*6; is given=324; while(given<11) is false so loop exits given/=2; is given=given/2; is given=324/2; is given=162; while(given>40) is true so loop continues for 81 and 40 before exiting given*=3; is given=given*3; is given=40*3; is given=120; while(given<20) is false so loop exits for(int x=given;x<8;x++) increments x to 8 and exits
25th Jan 2018, 7:11 PM
John Wells
John Wells - avatar
+ 3
input of -1 causes given*=6 and while(given<11) to loop until overflow to positive number or timeout.
25th Jan 2018, 7:17 PM
John Wells
John Wells - avatar