Solved math exercises in PSeInt
12 examples
How it works
Many pseudocode exercises are maths problems: averages, areas, prime numbers, divisors. The operators are the usual ones (+, -, *, /, ^) plus MOD, which gives the remainder of a division.
MOD solves a surprising number of problems: n MOD 2 = 0 tells whether a number is even, and n MOD d = 0 whether d divides n. Trunc(n / 10) drops the last digit of a number.
For the rest there are ready-made functions: Raiz, Abs, Redon, Trunc, and constants like PI. Combined with a loop, they're enough to find primes, compute the greatest common divisor or add up a number's digits.
Short example
The least you need to see it work. Copy it or open it in the editor.
Algoritmo Divisors Definir n, d Como Entero Escribir "Type a number:" Leer n Escribir Sin Saltar "Divisors of ", n, ": " Para d <- 1 Hasta n Hacer Si n MOD d = 0 Entonces Escribir Sin Saltar d, " " FinSi FinPara Escribir ""FinAlgoritmoWhat it prints:
Type a number:User answer: 12Divisors of 12: 1 2 3 4 6 12
Opens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
Temperature Converter
Converts degrees Celsius to Fahrenheit and Kelvin.
BeginnerTip Calculator
Splits a restaurant bill, tip included.
BeginnerFibonacci Sequence
Prints the first terms of the Fibonacci sequence.
BeginnerBody Mass Index
Computes your BMI and classifies it as underweight, normal and so on.
IntermediateParking Fee
Charges every started hour, with a daily maximum.
IntermediatePrime Numbers
Finds every prime number up to a limit.
IntermediateGCD and LCM
Computes the greatest common divisor and the least common multiple.
IntermediateQuadratic Equation
Solves ax² + bx + c = 0, with real or complex roots.
IntermediateGeometry
Finds a circle's area and solves a right triangle.
IntermediateCompound Interest
Watch your savings grow year by year.
IntermediateCaesar Cipher
Encrypts a message by shifting each letter of the alphabet.
AdvancedBase Conversion
Writes a number in binary and hexadecimal.
Advanced
In the language reference
The instructions involved, explained one by one.
- MOD (%)PSeInt MOD operator: the remainder of a division
- Division (/)Division in PSeInt: the / operator
- Power (^)Powers in PSeInt: the ^ operator
- RaizPSeInt Raiz: square root
- TruncPSeInt Trunc: keep the whole part of a number
- RedonPSeInt Redon: round to the nearest whole number
- AbsPSeInt Abs: absolute value
Other concepts
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.