105k views
1 vote
Ok so apparently the answer is 6 but I dont know how, and I have my final tmrw so pls help, ty ​

Ok so apparently the answer is 6 but I dont know how, and I have my final tmrw so-example-1
User Latashia
by
5.3k points

1 Answer

2 votes

Well, the user enters the number 3, and the while loop adds the user entered value to sum. Now the sum is equal to 3. Then, the user entered value is equal to itself minus 1, which is 2. Two is then added to sum again, which equals 3+2 or 5. The user entered value is again subtracted by 1. It now equals 1. That 1 is added to sum and the sum is equal to 6. The user entered value is subtracted by 1 and it finally equals 0. The loop stops running because value is equal to 0 and the sum, which is 6, is printed to the screen. 6 is the output.

User Jellyfishhuang
by
5.5k points