84.0k views
4 votes
Assume that lo and hi each are associated with an integer and that result refers to 0. Write a while loop that adds the integers from lo up through hi (inclusive), and associates the sum with result. Your code should not change the values associated with lo and hi. Also, just use these variables: i, lo, hi, and result.

User Old Fox
by
5.2k points

1 Answer

3 votes

Answer:

The following are the program in the Python Programming Language

#declare a variable and initialize to 'lo'

i=lo

#declare a variable and initialize to '0'

result=0

#set a while loop that iterates from 'hi' to 'lo'

while(i<=hi):

#Then, add i with result and store it in result.

result=result+i

#increament in the variable 'i' by 1

i+=1

Step-by-step explanation:

The following are the description of the program.

  • Firstly, set the two variables that are 'i' and 'result', then, initialize in these variables to the variable 'lo' and '0'.
  • Set the while loop statement that iterates from the variable 'i' and stops at the variable 'hi'.
  • Finally, perform the addition with the variables 'result' and 'i' and store them in the variable 'result'. Then, increment in the variable 'i' by 1.
User Jzafrilla
by
5.5k points