C#.NET — Predict the output of: Console.WriteLine(13 / 2 + " " + 13 % 2);

Difficulty: Easy

Correct Answer: 6 1

Explanation:

Introduction / Context:This question checks knowledge of integer division and modulus operations in C#.

Given Data / Assumptions:

  • 13 / 2 with integer operands yields integer division (truncation).
  • 13 % 2 gives the remainder.

Concept / Approach:In C#, when both operands are integers, division produces an integer result discarding the fractional part. The modulus operator % gives the remainder after division.

Step-by-Step Solution:

13 / 2 = 6 (fraction truncated). 13 % 2 = 1 (remainder). Console.WriteLine outputs: 6 1.

Verification / Alternative check:Running the code in Visual Studio prints 6 1.

Why Other Options Are Wrong:6.5 values are wrong since floating division only occurs if at least one operand is float/double.

Common Pitfalls:Expecting fractional result without casting operands to float/double.

Final Answer:6 1

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion