40187: Assume the int variables i, lo, hi and result have been declared and that lo and hi have been initialized. Assume further tha result has been initialzied to the value 0. Write a for loop that adds the integers between lo and hi (inclusive), and stores the result in result. Your code should not change the values of lo and hi. Also, do not declare any additional variables -- use only i, lo, hi, and result.
For i = lo to hi
result += i
Next
40223: Give that two Integer variables, total and amount have been declared, write a loop that reads non-negative values into amount and adds them into total. The loop termiantes when a value less tha 0 is read into amount. Don't forget to initialize total to 0. To read a value into amount use a method, getNum() that we provide for you a class named tC: amount = TC.getNum();
total = 0
amount = 0
Do
total += amount
amount = TC.getNum()
Loop Until (amount < 0)
No comments:
Post a Comment