Bird
Raised Fist0
R Programmingprogramming~20 mins

Arithmetic operators in R Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Arithmetic Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of mixed arithmetic operations
What is the output of this R code snippet?
R Programming
result <- 5 + 3 * 2^2 - 4 / 2
print(result)
A[1] 11
B[1] 12
C[1] 14
D[1] 15
Attempts:
2 left
💡 Hint
Remember the order of operations: exponentiation, multiplication/division, addition/subtraction.
❓ Predict Output
intermediate
2:00remaining
Result of integer division and modulus
What is the output of this R code?
R Programming
a <- 17
b <- 5
cat(a %/% b, a %% b)
A3 2
B2 3
C3 3
D2 2
Attempts:
2 left
💡 Hint
Integer division %/% gives quotient, modulus %% gives remainder.
🔧 Debug
advanced
2:00remaining
Identify the error in arithmetic expression
What error does this R code produce?
R Programming
x <- 10
y <- 0
z <- x / y
print(z)
A[1] Inf
BNaN
CError: division by zero
D0
Attempts:
2 left
💡 Hint
Check how R handles division by zero with numeric values.
❓ Predict Output
advanced
2:00remaining
Output of combined arithmetic and logical operators
What is the output of this R code?
R Programming
a <- 4
b <- 2
result <- (a > b) + (b == 2) * 3
print(result)
A[1] 5
B[1] 3
C[1] 4
D[1] 1
Attempts:
2 left
💡 Hint
Logical TRUE is 1 and FALSE is 0 in arithmetic operations.
🧠 Conceptual
expert
2:00remaining
Number of elements in a vector after arithmetic recycling
Given the code below, how many elements does the resulting vector have?
R Programming
v1 <- c(1, 2, 3, 4, 5)
v2 <- c(10, 20)
result <- v1 + v2
A2
B5
C10
DError due to length mismatch
Attempts:
2 left
💡 Hint
R recycles shorter vectors to match the length of longer vectors.

Practice

(1/5)
1. Which of the following operators in R is used for multiplication?
easy
A. -
B. +
C. *
D. /

Solution

  1. Step 1: Recall basic arithmetic operators in R

    In R, * is used for multiplication, + for addition, - for subtraction, and / for division.
  2. Step 2: Identify the multiplication operator

    The operator * multiplies two numbers.
  3. Final Answer:

    * -> Option C
  4. Quick Check:

    Multiplication operator = * [OK]
Hint: Remember * means multiply in math and R [OK]
Common Mistakes:
  • Confusing * with + or -
  • Using / for multiplication
  • Using ^ for multiplication
2. Which of the following is the correct syntax to calculate the remainder of 10 divided by 3 in R?
easy
A. 10 %% 3
B. 10 /% 3
C. 10 %/% 3
D. 10 % 3

Solution

  1. Step 1: Understand remainder operator in R

    In R, the operator %% gives the remainder after division.
  2. Step 2: Identify correct syntax for remainder

    10 %% 3 calculates remainder of 10 divided by 3, which is 1.
  3. Final Answer:

    10 %% 3 -> Option A
  4. Quick Check:

    Remainder operator = %% [OK]
Hint: Use %% for remainder, not % or /% [OK]
Common Mistakes:
  • Using single % instead of %%
  • Confusing integer division %/% with remainder %%
  • Typing operators incorrectly like /%
3. What is the output of the following R code?
result <- 5 + 3 * 2
print(result)
medium
A. 16
B. 11
C. 10
D. 13

Solution

  1. Step 1: Apply operator precedence in R

    Multiplication (*) has higher priority than addition (+), so 3 * 2 = 6 is calculated first.
  2. Step 2: Calculate the expression

    Then add 5 + 6 = 11.
  3. Final Answer:

    11 -> Option B
  4. Quick Check:

    5 + (3 * 2) = 11 [OK]
Hint: Multiply before adding due to operator precedence [OK]
Common Mistakes:
  • Adding before multiplying
  • Ignoring operator precedence
  • Calculating 5 + 3 first
4. Identify the error in this R code snippet:
value <- 10 %/ 3
print(value)
medium
A. Syntax error due to incorrect operator
B. Runs correctly and prints 3
C. Runs correctly and prints 1
D. Runtime error due to division by zero

Solution

  1. Step 1: Check the operator used

    The operator %/ is not valid in R. Integer division uses %/%.
  2. Step 2: Identify the error type

    Using %/ causes a syntax error because R does not recognize it.
  3. Final Answer:

    Syntax error due to incorrect operator -> Option A
  4. Quick Check:

    Integer division operator is %/% not %/ [OK]
Hint: Use %/% for integer division, not %/ [OK]
Common Mistakes:
  • Typing %/ instead of %/%
  • Confusing remainder %% with integer division
  • Expecting output despite syntax error
5. You want to calculate the integer division and remainder of 17 divided by 4 in R. Which code correctly assigns both results to variables int_div and rem?
hard
A. int_div <- 17 %/ 4
rem <- 17 %% 4
B. int_div <- 17 %% 4
rem <- 17 %/% 4
C. int_div <- 17 / 4
rem <- 17 % 4
D. int_div <- 17 %/% 4
rem <- 17 %% 4

Solution

  1. Step 1: Recall operators for integer division and remainder

    Integer division uses %/% and remainder uses %% in R.
  2. Step 2: Match operators to variables

    int_div <- 17 %/% 4 correctly assigns integer division result (4).
    rem <- 17 %% 4 correctly assigns remainder (1).
  3. Final Answer:

    int_div <- 17 %/% 4; rem <- 17 %% 4 -> Option D
  4. Quick Check:

    Integer division %/% and remainder %% used correctly [OK]
Hint: Use %/% for int division, %% for remainder [OK]
Common Mistakes:
  • Swapping operators for int division and remainder
  • Using invalid operator %/
  • Using / instead of %/% for integer division
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard