← Operators & Expressions

Integer vs. True Division

hard

Read two integers a and b and print both ways of dividing them: plain truncating integer division on the first line, and the real (non-truncating) division, rounded to 2 decimal places, on the second.

The first line is just a / b – both operands are already int, so it truncates on its own. The second line is the one to be deliberate about: a / b alone would still compute the truncated integer result first and only convert it to a double afterward, by which point the remainder is already gone. You need a cast on at least one operand – (double)a / b – to make the division itself happen in floating point, exactly as covered at the end of the lesson.

Your solution

"Run" uses the sample stdin ("7 2"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution