Assignment 1 1
Assignment 1 1
05-06-2025
Q1. Trace through this nested loop:
BEGIN
result = 0
FOR i = 1 TO 4
FOR j = 1 TO i
result = result + j
END FOR i
PRINT result
END
A) 10 B) 15 C) 20 D) 25
BEGIN
n = 729
count = 0
WHILE n > 1
n = n / 3
count = count + 1
END WHILE
PRINT count
END
A) 6 B) 5 C) 4 D) 7
BEGIN
n = 4
FOR i = 1 TO n
FOR j = 1 TO (n - i + 1)
PRINT j
END FOR j
PRINT NEWLINE
END FOR i
END
A) 8 B) 10 C) 12 D) 16
Q4. What will this pseudocode output?
BEGIN
a = 7, b = 3
FOR k = 1 TO 5
temp = a % b
a = b
b = temp
IF b == 0
BREAK
END IF
END FOR
PRINT a
END
A) 0 B) 1 C) 3 D) 7
BEGIN
result = 1
FOR i = 2 TO 6
FOR j = 1 TO i
IF j % 2 == 1
result = result * j
END IF
END FOR j
END FOR i
PRINT result
END
BEGIN
n = 64
result = 0
WHILE n > 0
IF n % 2 == 1
result = result + 1
END IF
n = n / 2
END WHILE
PRINT result
END
A) 1 B) 2 C) 6 D) 64
BEGIN
base = 2, exp = 8
result = 1
WHILE exp > 0
IF exp % 2 == 1
result = result * base
END IF
base = base * base
exp = exp / 2
END WHILE
PRINT result
END
A) 16 B) 64 C) 128 D) 256
Q8. What does this pseudocode calculate?
BEGIN
num = 28
sum = 0
FOR i = 1 TO num-1
IF num % i == 0
sum = sum + i
END IF
END FOR
IF sum == num
PRINT "PERFECT"
ELSE
PRINT "NOT PERFECT"
END IF
END
BEGIN
x = 3, y = 4, z = 5
result = 0
FOR i = 1 TO 3
FOR j = 1 TO i
result = result + (x * i + y * j + z)
END FOR j
END FOR i
PRINT result
END
A) 87 B) 96 C) 112 D) 114
Q10. Determine the sequence generated:
BEGIN
a = 0, b = 1
PRINT a, b
FOR i = 1 TO 5
c = a + b
PRINT c
a = b
b = c
END FOR
END
A) 5 B) 8 C) 13 D) 21
BEGIN
FOR i = 1 TO 4
FOR j = 1 TO 4
IF i == j OR i + j == 5
PRINT "1"
ELSE
PRINT "0"
END IF
END FOR j
PRINT NEWLINE
END FOR i
END
A) 0 B) 1 C) 2 D) 3
Q12. Determine the pattern:
BEGIN
FOR i = 1 TO 4
spaces = 4 - i
FOR j = 1 TO spaces
PRINT " "
END FOR j
FOR k = 1 TO (2 * i - 1)
PRINT "*"
END FOR k
PRINT NEWLINE
END FOR i
END
A) 5 B) 6 C) 7 D) 8
BEGIN
age = 17
hasLicense = TRUE
IF age >= 18 OR hasLicense
IF age >= 16
PRINT "Can Drive"
ELSE
PRINT "Too Young"
END IF
ELSE
PRINT "Cannot Drive"
END IF
END
A) 14 B) 15 C) 16 D) 24
BEGIN
a = 3, b = 7
a = a XOR b
b = a XOR b
a = a XOR b
PRINT a, b
END
A) 3, 7 B) 7, 3 C) 4, 4 D) 0, 10
BEGIN
total = 0
multiplier = 1
FOR i = 1 TO 4
total = total + (i * multiplier)
multiplier = multiplier * 2
END FOR
PRINT total
END
A) 15 B) 20 C) 49 D) 30
Q17. Determine the output:
BEGIN
value = 100
WHILE value > 1
IF value % 2 == 0
value = value / 2
ELSE
value = value * 3 + 1
END IF
END WHILE
PRINT value
END
A) 0 B) 1 C) 2 D) 4
BEGIN
result = 0
FOR outer = 1 TO 3
FOR inner = outer TO 3
result = result + (outer * inner)
END FOR inner
END FOR outer
PRINT result
END
A) 25 B) 30 C) 35 D) 40
Q19. Analyze this complex loop:
BEGIN
sum = 0
i = 1
WHILE i <= 10
j = i
WHILE j <= 10
sum = sum + 1
j = j + 2
END WHILE
i = i + 1
END WHILE
PRINT sum
END
A) 35 B) 30 C) 40 D) 45
BEGIN
total = 0
FOR i = 1 TO 4
subtotal = 0
FOR j = 1 TO i
subtotal = subtotal + j
END FOR j
total = total + subtotal
END FOR i
PRINT total
END
A) 20 B) 25 C) 30 D) 35
Q21. Analyze this pattern:
BEGIN
value = 0
FOR i = 1 TO 3
FOR j = 1 TO 3
IF i == j
value = value + (i + j)
ELSE
value = value + 1
END IF
END FOR j
END FOR i
PRINT value
END
A) 15 B) 18 C) 21 D) 24
BEGIN
result = 0
FOR level1 = 1 TO 3
FOR level2 = level1 TO 4
result = result + (level1 * level2)
END FOR level2
END FOR level1
PRINT result
END
A) 50 B) 55 C) 49 D) 65
23. What will this string operation produce?
BEGIN
text = "HELLO"
result = ""
FOR i = 1 TO LENGTH(text)
char = SUBSTRING(text, i, 1)
result = char + result
END FOR
PRINT result
END
BEGIN
word = "PROGRAMMING"
vowel_count = 0
FOR i = 1 TO LENGTH(word)
char = SUBSTRING(word, i, 1)
IF char IN ["A", "E", "I", "O", "U"]
vowel_count = vowel_count + 1
END IF
END FOR
PRINT vowel_count
END
A) 2 B) 3 C) 4 D) 5
Q25. Determine the output:
BEGIN
a = 4
b = 0
c = 2
IF (a > 3) AND (b != 0) AND ((a / b) > c)
PRINT "Pass"
ELSE
PRINT "Fail"
END IF
END