Cambridge AS Computer Science

Basics of Pseudocode

Data Types

In pseudocode, data types play an essential role in defining the kind of values that variables can store and process. Understanding data types is important for writing clear and accurate algorithms, as they determine how data is handled within a program. In this section, we will explore the different data types used in pseudocode, along with their meaning and examples, as required in the Cambridge AS Level Computer Science syllabus. Different components used in pseudocode are explained below. DATATYPES
DATA TYPE DESCRIPTION EXAMPLES
INTEGER a whole number 15, 0, 27, 155
REAL a number contains fractional part 3.14, 1.0, 17.5
CHAR a single character 'A', 'c', '5', '@'
STRING a sequence of zero or more characters "Computer", "exam", "abc123"
BOOLEAN logical values TRUE, FALSE
DATE a calendar date '17/10/1995', 01/12/2026

Declaring Variables

Examples:
1. Declare integer variables and assigning values:
DECLARE age : INTEGER
DECLARE mark : INTEGER
age ← 15
mark ← 45
2. Declare and initialise Real variable:
DECLARE percentage : REAL
percentage ← 70.5
3. Declaring a char variable to store the grades of a student:
DECLARE grade : CHAR
grade ← 'B'
4. Declaring and initialising string variable:
DECLARE place : STRING
place ← "Sydney"
5. Declaring and initialising a boolean variable:
DECLARE flag : BOOLEAN
flag ← TRUE
6. Declaring and initialising a variable of type DATE:
DECLARE date_of_birth : DATE
date_of_birth ← 15/10/2005
Example #1: Write the pseudocode to calculate the sum of 10 numbers.
DECLARE sum: INTEGER DECLARE number: INTEGER sum ← 0 FOR count ← 1 TO 10 OUTPUT "Enter a number: " INPUT number sum ← sum + number NEXT count OUTPUT "Sum of 10 numbers:", sum
OUTPUT:
Enter a number: 10 Enter a number: 5 Enter a number: 5 Enter a number: 30 Enter a number: 12 Enter a number: 30 Enter a number: 100 Enter a number: 2 Enter a number: 44 Enter a number: 14 Sum of 10 numbers: 252

Get In Touch

123 Street, New York, USA

info@ictmadesimple.com

+012 345 67890

Newsletter

Follow Us

© www.ictmadesimple.com. All Rights Reserved.