IF THEN ELSE ENDIF Beginners
IF THEN ELSE ENDIF Beginners
In a simple pseudo code program, you want to check if a user's age is greater than or
equal to 18. If it is, the program should display "You are an adult," and if not, it should
display "You are a minor." Write the pseudo code for this program using
"IF...THEN...ELSE...ENDIF" statements.
IF
AGE > =18
THEN
OUTPUT “YOU ARE AN ADULT”
ELSE
OUTPUT “YOU ARE A MINOR”
END IF
DECLARE
STUDENT MARKS = X
IF
STUDENT MARKS >= 60
THEN
OUTPUT “PASS”
ELSE
OUTPUT “FAIL”
END IF
"Write pseudo code that uses the IF...THEN...ELSE...ENDIF structure to determine whether a given
number is even or odd. Additionally, include a condition to check if the number is negative or
positive and provide different outputs based on these conditions. Explain the logic and flow of
your pseudo code."
IF
Number = “/ by 2”
OUTPUT
“EVEN”
ELSE
OUTPUT “ODD”
IF Number > 0
OUTPUT
“POSITIVE”
ELSE
OUTPUT
“NEGITIVE”
END IF
END IF
Sure, here's a beginner-level pseudo code question involving the CASE OF... OTHERWISE...
ENDCASE construct:
**Question:**
In a simple pseudo code program, you are given a variable `userChoice` which can have values
'A', 'B', 'C', or 'D'. You need to implement a program that uses the CASE OF... OTHERWISE...
ENDCASE structure to perform different actions based on the value of `userChoice`. If the value
is 'A', the program should display "Option A selected." If the value is 'B', it should display
"Option B selected." If the value is 'C', it should display "Option C selected." If the value is 'D', it
should display "Option D selected." For any other value of `userChoice`, the program should
display "Invalid option." Write the pseudo code for this program using the CASE OF...
OTHERWISE... ENDCASE structure.
OTHERWISE
OUTPUT
“Invalid option”
END CASE
Question: Write pseudo code that uses the CASE OF ... OTHERWISE ... ENDCASE
structure to determine the day of the week based on a numeric input (1 for Sunday, 2 for
Monday, and so on). Additionally, explain how you would handle cases where the input is not
within the valid range of 1 to 7.
FOR counter 1 to 10
output “count”
NEXT
Write a simple FOR...TO...NEXT loop in pseudo code that counts from 1 to 5 and displays the
current count on each iteration. Explain how this loop works step by step, and what the final
output will be.
FOR COUNTER 1 TO 5
OUTPUT
“COUNT + COUNTER”
NEXT
FOR … TO … NEXT loops INTERMEDIATE
Write a pseudo code snippet using a FOR...TO...NEXT loop to iterate through the numbers from 1
to 10 and print the square of each number. Explain how the loop works and what the expected
output will be.
FOR COUNTER 1 TO 10
OUTPUT
‘’The square of’’ +’’is’’ +(counter *counter)
NEXT
Write a pseudo code program that uses a FOR...TO...NEXT loop to calculate the sum of all even
numbers between 1 and 50 (inclusive). Explain each part of your pseudo code, including the
initialization, condition, and incrementation of the loop variable.
IF number % 2 == 0 THEN
totalSum = totalSum + number Add the even number to the total sum
END IF
NEXT number
OUTPUT "The sum of even numbers between 1 and 50 is: " + totalSum