Write pseudo code to check if a number is positive and even.
Write pseudo code to print a 3Γ3 grid of asterisks using nested loops.
Write pseudo code to check if a number is both prime and odd.
What are the key properties of a one-dimensional array?
Write pseudo code to initialize an array with the first five even numbers.
Answers and Descriptions
Answer:
INPUT number
IF number > 0 THEN
IF number MOD 2 = 0 THEN
OUTPUT "Positive and even"
ELSE
OUTPUT "Positive but odd"
ENDIF
ELSE
OUTPUT "Not positive"
ENDIF
Description: Nested If statements check for positive and even conditions, demonstrating layered decision-making in programming.
Answer:
FOR i = 1 TO 3
FOR j = 1 TO 3
OUTPUT "*" + " "
ENDFOR
OUTPUT newline
ENDFOR
Description: Nested loops iterate over rows and columns to print a grid, testing the ability to manage multiple iteration levels.
Answer:
INPUT n
isPrime = TRUE
IF n MOD 2 = 1 THEN
FOR i = 2 TO SQRT(n)
IF n MOD i = 0 THEN
isPrime = FALSE
BREAK
ENDIF
ENDFOR
IF isPrime THEN
OUTPUT "Prime and odd"
ELSE
OUTPUT "Odd but not prime"
ENDIF
ELSE
OUTPUT "Not odd"
ENDIF
Description: This combines selection (odd check) and iteration (prime check), testing complex nested logic integration.
Answer: Index, contiguous locations, random access.
Description: A one-dimensional array stores elements linearly, accessed via indices (starting at 0), in contiguous memory, supporting efficient random access.Answer:
DECLARE array[5] AS INTEGER
array[0] = 2
array[1] = 4
array[2] = 6
array[3] = 8
array[4] = 10
Description: This pseudo code declares and assigns even numbers to an array, demonstrating basic array manipulation skills.