WDTPD - Looping

12 questions

Q1
What is the output?
n = 48
m = 18
WHILE m != 0
    temp = m
    m = n MOD m
    n = temp
END WHILE
OUTPUT n
Q2
What is the output?
x = 2
FOR i = 1 TO 4
    x = x * x
NEXT i
OUTPUT x
Q3
What is the output?
s = 0
FOR i = 1 TO 5
    FOR j = 1 TO i
        s = s + 1
    NEXT j
NEXT i
OUTPUT s
Q4
What is the output?
x = 1
FOR i = 1 TO 5
    x = x * 2 + 1
NEXT i
OUTPUT x
Q5
What is the output?
count = 0
FOR i = 1 TO 4
    FOR j = i TO 4
        count = count + 1
    NEXT j
NEXT i
OUTPUT count
Q6
What is the output?
n = 583
sum = 0
WHILE n > 0
    sum = sum + n MOD 10
    n = INT(n / 10)
END WHILE
OUTPUT sum
Q7
What is the output?
a = 0
b = 1
FOR i = 1 TO 6
    temp = b
    b = a + b
    a = temp
NEXT i
OUTPUT b
Q8
What is the output?
n = 7
count = 0
WHILE n != 1
    IF n MOD 2 == 0 THEN
        n = n / 2
    ELSE
        n = 3 * n + 1
    END IF
    count = count + 1
END WHILE
OUTPUT count
Q9
How many times does the inner loop body execute?
FOR i = 1 TO 3
    FOR j = 1 TO 3
        IF i != j THEN
            (body)
        END IF
    NEXT j
NEXT i
Q10
What is the output?
n = 100
count = 0
WHILE n > 1
    n = INT(n / 3)
    count = count + 1
END WHILE
OUTPUT count
Q11
What is the output?
p = 1
FOR i = 5 TO 1 STEP -1
    p = p * i
NEXT i
OUTPUT p
Q12
What is the output?
s = 0
FOR i = 1 TO 6
    IF i MOD 2 == 0 THEN
        s = s + i
    END IF
NEXT i
OUTPUT s