2.11 . What is Z after execution? DELTA_Z = 0.5 Z=10 DOFOR J = 1, 500 Z = Z + DE
ID: 3781845 • Letter: 2
Question
2.11. What is Z after execution?
DELTA_Z = 0.5
Z=10
DOFOR J = 1, 500
Z = Z + DELTA_Z
IF Z > 40 THEN EXIT LOOP
ENDDO
2.12. What is Z after execution?
DELTA_Z = 0.5
Z=10
DOFOR J = 1, 500
Z_PREVIOUS = Z
Z = Z + DELTA_Z
IF Z*Z_PREVIOUS > 144 THEN EXIT LOOP
ENDDO
2.13. Write pseudocode to sum consecutive integers. Let the lowest integer be L and the highest be H,
and let both L and H be provided by the user.
2.14. Write pseudocode to sum consecutive even integers. Let the lowest even integer be L and the
highest even integer be H, and let both L and H be provided by the user.
2.15. Write pseudocode to sum consecutive odd integers. Let the lowest odd integer be L and the
highest odd integer be H, and let both L and H be provided by the user.
2.16. Write pseudocode to calculate the SUM of consecutive integers from the lowest, L, through the
highest, H, but without exceeding 100. If 100 would be exceeded, then let SUM reach as high as
possible a value without exceeding 100. Let L and H be provided by the user.
2.17. Write pseudocode to add one increment of time DELTA_T for each cycle to get a new value of
TOTAL for each cycle, until TOTAL reaches P*DELTA_T, where P is a whole number representing the
number of cycles. Let your initial value of TIME be 0. DELTA_T and P are INPUT values provided by the
user.
2.18. Write pseudocode to add one increment of time DELTA_T for each cycle to get a new value of
TOTAL for each cycle, until TOTAL reaches P*DELTA_T, but without exceeding 100. If 100 would be
exceeded, then let TOTAL reach as high as possible a value without exceeding 100. P is a whole number
representing the number of cycles that would be needed for TIME to reach P*DELTA_T. Let your initial
value of TIME be 0. DELTA_T and P are INPUT values provided by the user.
2.19. Write pseudocode to add one increment of time DELTA_T for each cycle to get a new value of
TOTAL for each cycle, until TOTAL reaches P*DELTA_T, but without the product of consecutive values of
TOTAL exceeding 100. If 100 would be exceeded, then let the product reach as high as possible a value
without exceeding 100. P is a whole number representing the number of cycles that would be needed
for TIME to reach P*DELTA_T. Let your initial value of TIME be 0. DELTA_T and P are INPUT values
provided by the user.
Explanation / Answer
Answer - 2.11
DELTA_Z = 0.5
Z=10
DO FOR J = 1, 500
Z = Z + DELTA_Z
IF Z > 40 THEN EXIT LOOP
ENDDO
In each iteration z increments by 0.5 and after 30th iteration z becomes 40,
but 40 is not greater than 40 so that iteration continues.
In 31st iteration z becomes 40.5 and as it is greater than 40 , iteration will stop.
Thus, after execution z becomes 40.5
Answer - 2.12
DELTA_Z = 0.5
Z=10
DO FOR J = 1, 500
Z_PREVIOUS = Z
Z = Z + DELTA_Z
IF Z*Z_PREVIOUS > 144 THEN EXIT LOOP
ENDDO
In each iteration z increments by 0.5 and after 4th iteration z becomes 12 and z * z_previous will become 144
but 144 is not greater than 144 so that iteration continues.
In 5th iteration z becomes 12.5 and z * z_previous will become 150 and as it is greater than 144, iteration will stop
Thus, after execution z becomes 12.5
Answer - 2.13
Procedure Consecutive_Integer_Sum
L = READ ; //take input from user for L
H = READ ; //take input from user for H
sum = 0;
For j = (L + 1) to H
sum = sum + (j - 1) + j; //summing two consecutive integers
j = j + 1; // increment loop variable j by 1 (one)
End_For
print("Sum of consecutive integers : ",sum);
End_Consecutive_Integer_Sum
In this procedure, I have started iteration from (L + 1) as I have added two consecutive integers as (j-1) (previous)
and j (current)
Answer - 2.14
Procedure Sum_Consecutive_Even_Integer
L = READ ; //take input from user for L
H = READ ; //take input from user for H
sum = 0 ;
For j = L to (H - 2) //previous even integer of H
sum = sum + j + (j + 2); //current even integer and next even integer
j = j + 2; // increment loop variable j by 2 (two) to point next even integer
End_For
print("Sum of consecutive even integer : ",sum);
End_Sum_Consecutive_Even_Integer
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.