Lesson 3 of 16

Arithmetic

Arithmetic Operators

R supports all standard arithmetic operators:

OperatorDescriptionExample
+Addition5 + 3 is 8
-Subtraction5 - 3 is 2
*Multiplication5 * 3 is 15
/Division7 / 2 is 3.5
%%Modulo (remainder)7 %% 2 is 1
%/%Integer division7 %/% 2 is 3
^Exponentiation2 ^ 3 is 8

Math Functions

R has many built-in math functions:

cat(abs(-5), "\n")    # 5
cat(sqrt(16), "\n")   # 4
cat(ceiling(3.2), "\n") # 4
cat(floor(3.8), "\n")   # 3
cat(round(3.567, 2), "\n") # 3.57

Type Coercion

R automatically converts types in arithmetic:

cat(TRUE + 1, "\n")   # 2 (TRUE becomes 1)
cat(FALSE + 1, "\n")  # 1 (FALSE becomes 0)

Your Task

Calculate and print the following on separate lines:

  1. 17 modulo 5
  2. 2 to the power of 10
  3. The square root of 144
R runtime loading...
Loading...
Click "Run" to execute your code.