Library Routines
Library routines are pre-written code that can be used in programs to perform specific tasks.
- Using library routines saves time by not having to write code from scratch
- Library routines are also tested and proven to work, so errors are less likely
- Some commonly used library routines include:
- Input/output routines
- Maths routines
- Libraries can be included in programs by importing them
- The specific syntax for importing a library may vary depending on the programming language being used
- It is important to check the documentation for a library to understand its usage and available functions
Maths routines
- MOD: a function that returns the remainder when one number is divided by another number
- Pseudocode example:
x MOD y
- Python example:
x % y
- Java example:
x % y
- Visual Basic example:
x Mod y
- Pseudocode example:
- DIV: a function that returns the quotient when one number is divided by another number
- Pseudocode example:
x DIV y
- Python example:
x // y
- Java example:
x / y
- Visual Basic example:
x \ y
- Pseudocode example:
- ROUND: a function that rounds a number to a specified number of decimal places
- Pseudocode example:
ROUND(x, n)
- Python example:
round(x, n)
- Java example:
Math.round(x * 10^n) / x;
- Visual Basic example:
Math.Round(x, n)
- Pseudocode example:
- RANDOM: a function that generates a random number between x and n
- Pseudocode example:
RANDOM(x,n)
- Python example:
random.randint(x,n)
- Java example:
rand.nextInt(x)
- Visual Basic example:
rand.next(x,n)
- Pseudocode example:
Exam Tip
- Remember to import or include the appropriate library before using the routines in your code