# Common Operations &amp; Built-in Functions

> Cambridge Assessment International Education (CAIE) Pseudocode Reference Guide
> Applicable Syllabus: **IGCSE &amp; A Level**

Cambridge pseudocode I/O routines, arithmetic (DIV/MOD), relational operators, Boolean logic, and unified string &amp; numeric built-in functions.

---

Standard input/output commands, arithmetic operators, relational and Boolean logic, and unified string &amp; numeric built-in functions.

### 5.1 Input &amp; Output

```pseudocode
// runnable
// Input and output demo
DECLARE Answer, Score, Lives : INTEGER
Score &lt;- 10
Lives &lt;- 3
INPUT Answer
OUTPUT &quot;Your answer: &quot;, Answer
OUTPUT Score
OUTPUT &quot;You have &quot;, Lives, &quot; lives left&quot;
```

### 5.2 Arithmetic Operators

| Operator | Description |
|----------|-------------|
| `+` | Addition |
| `-` | Subtraction |
| `*` | Multiplication |
| `/` | Division (result is always REAL) |
| `DIV` | Integer division (quotient only) |
| `MOD` | Modulus (remainder after division) |

### 5.3 Relational Operators

| Operator | Description |
|----------|-------------|
| `&gt;` | Greater than |
| `&lt;` | Less than |
| `&gt;=` | Greater than or equal to |
| `&lt;=` | Less than or equal to |
| `=` | Equal to |
| `&lt;&gt;` | Not equal to |

The result of relational operations is always of data type `BOOLEAN`.

### 5.4 Logic Operators

The logic operators are `AND`, `OR`, and `NOT`. Operands and results are always `BOOLEAN`. Use parentheses to make order of operations explicit.

### 5.5 String Functions &amp; Operations

| Function Signature | Description | Example | Syllabus |
|--------------------|-------------|---------|----------|
| `LENGTH(s : STRING) RETURNS INTEGER` | Returns string length | `LENGTH(&quot;Happy Days&quot;)` -&gt; `10` | Both |
| `MID(s : STRING, x : INTEGER, y : INTEGER) RETURNS STRING` | Returns y chars from position x | `MID(&quot;ABCDEFGH&quot;, 2, 3)` -&gt; `&quot;BCD&quot;` | 9618 |
| `RIGHT(s : STRING, x : INTEGER) RETURNS STRING` | Returns rightmost x chars | `RIGHT(&quot;ABCDEFGH&quot;, 3)` -&gt; `&quot;FGH&quot;` | 9618 |
| `LEFT(s : STRING, x : INTEGER) RETURNS STRING` | Returns leftmost x chars | `LEFT(&quot;CAMBRIDGE&quot;, 3)` -&gt; `&quot;CAM&quot;` | 0478 |
| `SUBSTRING(s : STRING, x : INTEGER, y : INTEGER) RETURNS STRING` | Extracts y chars from position x | `SUBSTRING(&quot;HELLO&quot;, 2, 3)` -&gt; `&quot;ELL&quot;` | 0478 |
| `LCASE(c : CHAR) RETURNS CHAR` | Returns lower-case equivalent | `LCASE(&#39;W&#39;)` -&gt; `&#39;w&#39;` | Both |
| `UCASE(c : CHAR) RETURNS CHAR` | Returns upper-case equivalent | `UCASE(&#39;h&#39;)` -&gt; `&#39;H&#39;` | Both |
| `&amp;` (concatenation) | Joins two strings | `&quot;Summer&quot; &amp; &quot; Pudding&quot;` -&gt; `&quot;Summer Pudding&quot;` | Both |

### 5.6 Numeric Functions

| Function Signature | Description | Example | Syllabus |
|--------------------|-------------|---------|----------|
| `INT(x : REAL) RETURNS INTEGER` | Returns integer part of x | `INT(27.5415)` -&gt; `27` | Both |
| `RAND(x : INTEGER) RETURNS REAL` | Random real in range 0 to x (exclusive) | `RAND(87)` may return `35.43` | 9618 |
| `NUM_TO_STR(x) RETURNS STRING` | Converts number to string | `NUM_TO_STR(42)` -&gt; `&quot;42&quot;` | 0478 |
| `STR_TO_NUM(s : STRING) RETURNS NUMERIC` | Parses string to number | `STR_TO_NUM(&quot;42&quot;)` -&gt; `42` | 0478 |
| `ROUND(x : REAL, places : INTEGER) RETURNS REAL` | Rounds to the given number of decimal places | `ROUND(7.246, 2)` -&gt; `7.25` | 0478 |
| `RANDOM() RETURNS REAL` | Random real between 0 and 1 | `RANDOM()` may return `0.64` | 0478 |


---

* Previous Topic: [User-Defined Data Types](https://csmasters.dev/docs/pseudocode/user-defined-types.md)
* Next Topic: [Selection (IF &amp; CASE OF)](https://csmasters.dev/docs/pseudocode/selection.md)
