What is P after execution Assume that Z is any integer great
What is P after execution? Assume that Z is any integer greater than 2. (without inputing actual values keep Z in the final answer)
INPUT Z
P = 3
DOFOR K = 2, Z
P = P + K
ENDDO
Solution
On every iteration of the loop the value of k gets added to P. So values form 2 to z gets added which means total sum is (z(z+1)/2) - 1 (because k starts from 2) and initially P is 3 so add 3
Thus p after execution will be
p = p+(z(z+1)/2)-1
For example if z=5, value in p will be 3+2+3+4+5= 17
To confirm p = 3 +(5*6)/2 -1 = 3+15-1 = 17

