Ask Question

The following program segment is designed to compute the product of two nonnegative integers X and Y by accumulating the sum of X copies of Y; that is, 3 times 4 is computed by accumulating the sum of three 4s.

Is the program segment correct? Explain your answer.

Product ←0;

Count ←0;

repeat (Product ←Product + Y,

Count ←Count + 1)

until (Count = X)

+4
Answers (1)
  1. 23 July, 07:08
    0
    The program is correct: at the beginning, product = 0. Then, we start summing Y to that variable, and we sum Y exactly X times, because with each iteration we increase Count by 1, and check if Count=X so that we can exit the loop.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “The following program segment is designed to compute the product of two nonnegative integers X and Y by accumulating the sum of X copies of ...” 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