Lesson 3 of 15

Arithmetic

Arithmetic

Lua supports the usual arithmetic operators:

print(10 + 3)   -- 13
print(10 - 3)   -- 7
print(10 * 3)   -- 30
print(10 / 3)   -- 3.3333333333333
print(10 % 3)   -- 1
print(2 ^ 10)   -- 1024

The math library provides common functions:

print(math.floor(3.7))  -- 3
print(math.ceil(3.2))   -- 4
print(math.abs(-5))     -- 5
print(math.sqrt(16))    -- 4
print(math.max(1, 5))   -- 5
print(math.min(1, 5))   -- 1

Your Task

Compute and print the results of the given expressions.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.