Numbers and Math
Arithmetic Operators
Operator
Description
Inputs:
#Assigning values to variables
n1 = 7
n2 = 3
#Testing operators
cat(n1, "+", n2, "=", n1 + n2, "\n") # Addition
cat(n1, "-", n2, "=", n1 - n2, "\n") # Subtraction
cat(n1, "*", n2, "=", n1 * n2, "\n") # Multiplication
cat(n1, "/", n2, "=", n1 / n2, "\n") # Division
cat(n1, "/", n2, "=", sprintf("%.2f", n1 / n2), "\n") # Print to 2 decimal places
cat(n1, "^", n2, "=", n1 ^ n2, "\n") # Power/Exponent
cat(n1, "%%", n2, "=", n1 %% n2, "\n") # Remainder/ModuloOutputs:
Comparison Operators
Operator
Description
Resources
Last updated
