Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q5 of 15
Ruby - Operators and Expressions
What will be the output of this Ruby code?
result = 7 % 4
puts result
A1
B3
C4
D7
Step-by-Step Solution
Solution:
  1. Step 1: Calculate remainder of 7 divided by 4

    7 divided by 4 is 1 remainder 3.
  2. Step 2: The % operator returns the remainder

    So, 7 % 4 equals 3.
  3. Final Answer:

    3 -> Option B
  4. Quick Check:

    Remainder operator % = 3 [OK]
Quick Trick: Use % to find remainder after division [OK]
Common Mistakes:
  • Confusing remainder with quotient
  • Using / instead of %
  • Misreading the numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes