Pascal - 1

Question:

If M (x, y) is the statement "x is greater than y", and there is a row in the following pseudo Pascal:

while M (x, y) do
begin
x: = x - 10;
y: = y + 2;
end;

with prices in the first and x = 70 y = 5, y was the price after the row out of the while loop?
A. 11
B. 15
C. 17
D. 21
E. 25

Discussion:

OK ... we will study the above questions.
Note that the while loop has a condition "x is greater than y".
So during these requirements met (Condition TRUE value) then the looping will continue to run.
And the looping process will stop when the condition is not met (value FALSE) Note the way the following:

x = 70, y = 5
Check (x> y) -> (70> 5) -> TRUE
x = x - 10 = 70 - 10 = 60
y = y + 2 = 5 + 2 = 7
Check (x> y) -> (60> 7) -> TRUE
x = x - 10 = 60 - 10 = 50
y = y + 2 = 7 + 2 = 9
Check (x> y) -> (50> 9) -> TRUE
x = x - 10 = 50 - 10 = 40
y = y + 2 = 9 + 2 = 11
Check (x> y) -> (40> 11) -> TRUE
x = x - 10 = 40 - 10 = 30
y = y + 2 = 11 + 2 = 13
Check (x> y) -> (30> 13) -> TRUE
x = x - 10 = 30 - 10 = 20
y = y + 2 = 13 + 2 = 15
Check (x> y) -> (20> 15) -> TRUE
x = x - 10 = 20 - 10 = 10
y = y + 2 = 15 + 2 = 17
Check (x> y) -> (10> 17) -> FALSE
STOP

After a while looping process is complete, the final value of y is 17 (Best in the right C).

Source : Rosihan Ari’s Blog at blog.rosihanari.net (edited)

0 comments:

Post a Comment

Visitors


counter

Translate it

Followers

User


counter