+ 3

its very confusing...its answer should be 10 ...why is it 8????

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

5th Jan 2018, 5:56 PM
PRO
PRO - avatar
5 Answers
+ 3
plz help me fast
5th Jan 2018, 5:56 PM
PRO
PRO - avatar
+ 3
here you have three variables num number and total with values 2,2, and 0 respectively.. now in the loop.. u r checking that while num <=5 total+=number; num++ so when num=2; total=0+2=2 when num=3; total=2+2=4; when num=4 total=4+2=6; when num=5; total=6+2 i.e 8. now when num=6 loop terminates and final output is 8.
5th Jan 2018, 6:02 PM
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ 
ŠœŠ³. ŠšŠ½Š°ŠæšŸŒ  - avatar
+ 2
ver..ā˜ŗā˜ŗšŸ‘šŸ‘šŸ‘šŸ‘y very thanks to sami khan and ace ....u explained it very well...
5th Jan 2018, 6:07 PM
PRO
PRO - avatar
0
You should take for num = 1 instead of 2.
5th Jan 2018, 6:01 PM
Viereck
Viereck - avatar