In the following procedure, the parameter n is an integer greater than 2. Which of the following best describes the value returned by the procedure?
In the following procedure, the parameter n is an integer greater than 2. Which of the following best describes the value returned by the procedure?
Share
The procedure initially sets result to 1 and j to 2. In the REPEAT UNTIL loop, result is first assigned the sum of result and j, or 1 + 2. The value of j is then increased to 3. In each subsequent iteration of the loop, result is increased by each successive value of j (3, 4, 5, etc.) until j exceeds n. Therefore, the procedure returns the sum of the integers from 1 to n.