Professional Documents
Culture Documents
m=9 n=6
m=9+1=10
n=6-1=5
m=10+5=15
if (15>5), print m
m=15
Answer=15
Question 2
a=56 b=876
initial t=0
While loop is inside the function, the loop will keep going on if condition is true.
First iteration,
t = 0+56
= 56
b=876-1
= 875
Second iteration,
t = 56+56
= 112
b = 875-1
= 874
The iterations will keep going until b = 0. There are 876 times with 56 which equal 49056. While loop will
end and return the value of t which is 49056. Answer = b
Question 3
Inside the for loop, initial value n = 3, the loop will stop if n = 0. Every execution of code block the n will
decrease by 1.
First loop,
It will print n which is 3. Then, n will decrease by 1 become 2. After that, it goes through n = n -1, which
will return the values of n=1. End first loop.
Second loop,
Initial n = 1, it will print n and decrease by 1 become 0. After that, it goes through n= n-1 and return the
values of n= -1. End second loop.
It will never end the for loop, because n value will never become 0, and it will keep decreasing.
Question 4,
‘b’ = 98
‘a’ = 97
‘z’ = 122
Inside the while loop, we have (ch >= ‘a’ && ch <= ‘z’)
It means that (98 >= 97 && 98 <= 122) and it returns true for both conditions. Because of ch++, ASCII
values 98 increased by 1 to 99 which is ‘c’ after each execution.
Answer = b
Question 5
f=6 g=9
initial sum = 0
First loop,
sum = 0 + 6 = 6
Second loop,
sum = 6 + 7 = 13
Third loop,
sum = 13 + 8 = 21
After execution, n becomes 9. Loop will end because n cannot larger than 9.
Answer = a