Bird
0
0

You want to calculate the average of three numbers a, b, and c in Ruby. Which expression correctly uses arithmetic operators to do this?

hard📝 Application Q8 of 15
Ruby - Operators and Expressions
You want to calculate the average of three numbers a, b, and c in Ruby. Which expression correctly uses arithmetic operators to do this?
A(a * b * c) / 3
Ba + b + c / 3
C(a + b + c) / 3
Da + b + c % 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand average formula

    Average is sum of numbers divided by count.
  2. Step 2: Check operator precedence and grouping

    Parentheses ensure sum is calculated before division.
  3. Step 3: Evaluate options

    Only (a + b + c) / 3 correctly sums all then divides by 3.
  4. Final Answer:

    (a + b + c) / 3 -> Option C
  5. Quick Check:

    Average = sum / count [OK]
Quick Trick: Use parentheses to sum before dividing [OK]
Common Mistakes:
MISTAKES
  • Missing parentheses causing wrong order
  • Using multiplication instead of addition
  • Using % instead of division

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes