Ask Question
19 February, 07:05

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.

+2
Answers (1)
  1. 19 February, 07:27
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers