Write pseudocode statements for: expressions involving any of the arithmetic or logical operators input from the keyboard and output to the console

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – 11.1 Programming Basics

11.1 Programming Basics

Learning Objective

Write pseudocode statements that:

  • Read arithmetic or logical expressions from the keyboard.
  • Evaluate the expressions using the appropriate operators.
  • Display the result on the console.

Key Operators

CategoryOperatorPurposeExample
Arithmetic+Addition\$a + b\$
Arithmetic-Subtraction\$a - b\$
Arithmetic*Multiplication\$a * b\$
Arithmetic/Division\$a / b\$
ArithmeticmodModulo (remainder)\$a \bmod b\$
LogicalANDBoth conditions true\$x \; \text{AND} \; y\$
LogicalORAt least one condition true\$x \; \text{OR} \; y\$
LogicalNOTNegates a condition\$\text{NOT}\; x\$
Relational=, <>, <, >, ≤, ≥Comparison of values\$a \; \ge \; b\$

Pseudocode Syntax Conventions

For the purposes of this syllabus the following conventions are used:

  1. Input: READ variable – prompts the user and stores the value.
  2. Output: WRITE expression – displays the evaluated expression.
  3. Assignment: variable ← expression.
  4. Comments: # comment text.

Example 1 – Simple Arithmetic Expression

Read two numbers, compute their sum, product and remainder, then display the results.

# Example 1

READ a

READ b

sum ← a + b

product ← a * b

remainder ← a mod b

WRITE "Sum = " + sum

WRITE "Product = " + product

WRITE "Remainder = " + remainder

Example 2 – Logical Expression with Relational Operators

Determine whether a candidate passes an eligibility test based on age and score.

# Example 2

READ age

READ score

eligible ← (age ≥ 18) AND (score ≥ 70)

WRITE "Eligibility: " + eligible

Example 3 – Combined Arithmetic and Logical Operators

Calculate the average of three marks and decide if the student has passed.

# Example 3

READ m1

READ m2

READ m3

average ← (m1 + m2 + m3) / 3

passed ← average ≥ 50

WRITE "Average = " + average

WRITE "Passed? " + passed

Practice Questions

  1. Write pseudocode that reads an integer n and outputs whether n is a multiple of 5 or 7.

  2. Write pseudocode that reads two numbers x and y, computes (x² + y²) mod 10, and displays the result.

  3. Write pseudocode that reads a temperature in Celsius, converts it to Fahrenheit using \$F = \frac{9}{5}C + 32\$, and prints both values.

Suggested diagram: Flowchart showing the sequence of READ → CALCULATE → WRITE for a generic expression.