+ 1

Can u help with CS task? Is this correct?

is problem solving correct? how to solve this problem correct? (answer is 35) s = 0, n = 75; while s + n < 150 s = s + 15; n = n - 5; n = ? 1) 15-5=10 2) 75/10=7 3) 7*5=35 n = 35

25th Nov 2018, 12:20 AM
kamionick
kamionick - avatar
2 Answers
+ 2
Loop1: s = 0, n = 75, s+n = 75 Loop2: s = 15, n = 70, s+n = 85 Loop3: s = 30, n = 65, s+n = 95 So according to this logic, the loop should terminate when s+n = 155, which occurs on the 9th iteration, n would have been deducted by 5 for 8 times, which is a total of 5*8 = 40. The result of n would be 75-40 = 35. The rest of the iteration: Loop4: s = 45, n = 60, s+n = 105 Loop5: s = 60, n = 55, s+n = 115 Loop6: s = 75, n = 50, s+n = 125 Loop7: s = 90, n = 45, s+n = 135 Loop8: s = 105, n = 40, s+n = 145 Loop9: s = 120, n = 35, s+n = 155
25th Nov 2018, 12:57 AM
Hatsy Rei
Hatsy Rei - avatar
0
interesting question
24th Jan 2019, 10:36 PM
kamionick
kamionick - avatar