100 Pseudocode Questions and Answers for Interviews
1. Write pseudocode to check if a number is even or odd.
Answer:
BEGIN
INPUT number
IF number MOD 2 == 0 THEN
PRINT "Even"
ELSE
PRINT "Odd"
ENDIF
END
2. Write pseudocode to find the largest of three numbers.
Answer:
BEGIN
INPUT num1, num2, num3
IF num1 >= num2 AND num1 >= num3 THEN
PRINT "num1 is the largest"
ELSE IF num2 >= num1 AND num2 >= num3 THEN
PRINT "num2 is the largest"
ELSE
PRINT "num3 is the largest"
ENDIF
END
3. Write pseudocode to print the first 10 numbers in a Fibonacci sequence.
Answer:
BEGIN
SET a = 0, b = 1
PRINT a, b
FOR i FROM 1 TO 8 DO
SET temp = a + b
PRINT temp
SET a = b
SET b = temp
ENDFOR
END
4. Write pseudocode to calculate the factorial of a number using a loop.
Answer:
BEGIN
INPUT number
SET factorial = 1
FOR i FROM 1 TO number DO
factorial = factorial * i
ENDFOR
PRINT factorial
END
5. Write pseudocode to reverse an array.
Answer:
BEGIN
INPUT array
SET start = 0, end = LENGTH(array) - 1
WHILE start < end DO
SWAP array[start] WITH array[end]
INCREMENT start
DECREMENT end
ENDWHILE
PRINT array
END
6. Write pseudocode to check if a string is a palindrome.
Answer:
BEGIN
INPUT string
SET reversedString = REVERSE(string)
IF string == reversedString THEN
PRINT "Palindrome"
ELSE
PRINT "Not a Palindrome"
ENDIF
END
... (Include the next 94 questions and answers in a similar manner)