Skip to content
EspañolWorkspace →

PSeInt MOD operator: the remainder of a division

Gives the remainder (what's left over) of a whole-number division. Very handy to check whether a number is even (n MOD 2 = 0) or a multiple of another.

Group:
Algebraic
Template
MOD
Open it in Codoritmo

Opens the editor with this example loaded. Run it step by step and watch the flowchart.

Worked example

A complete algorithm, ready to copy and run.

mod-operator.psc · 3 lines
Algoritmo Example    Escribir 17 MOD 5FinAlgoritmo

Output

Shows: 2 (5 goes into 17 three times with 2 left over)

This is what the console shows when the example runs.

2

Good to know

Instead of MOD you can write %. The symbol works in every profile; the word MOD works in profiles that allow word operators, like the default one.

Some details depend on your school's profile. See the language profiles.

In a flowchart

This is how it appears in a flowchart, with the same shapes Codoritmo draws.

n MOD 2 = 0SíNo
Used inside a condition. It has no shape of its own; it's used inside a condition. Flowchart: a decision diamond with the condition "n MOD 2 = 0"; the Sí (yes) exit continues down and the No exit turns right.
Draw the flowchart of your own algorithm →

Template

The general form. Replace what's inside < > with your own data.

MOD · 1 line
MOD

Examples that use it

Programs from the example library where it appears, from the simplest to the most complete.

  • Parking Fee

    Charges every started hour, with a daily maximum.

    Intermediate
  • Prime Numbers

    Finds every prime number up to a limit.

    Intermediate
  • GCD and LCM

    Computes the greatest common divisor and the least common multiple.

    Intermediate
  • Caesar Cipher

    Encrypts a message by shifting each letter of the alphabet.

    Advanced
  • Base Conversion

    Writes a number in binary and hexadecimal.

    Advanced
  • ATM

    Checks your PIN and lets you check, deposit and withdraw money.

    Advanced
See every Math example →

More algebraic

Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.