Home Problems Volumes Ranking Forum Help News Mess 08:40:22

Rounding

Problem #6
Volumes:   Beginner's problems

Who solved this?

When program deals with numbers which have fraction part we sometimes want to round such values to whole integer. We'll need this for programming some later problems (to make answers more uniform, for example), so let us have the following dedicated exercise to learn this trick.

There are several pairs of numbers. For each pair you are to divide first by second and return the result, rounded to nearest integer.

In cases, when result contains exactly 0.5 as a fraction part, value should be rounded up (i.e. to next integer greater than given one). Note that for negative values "greater" means "closer to zero". Refer to the Wikipedia page on Rounding for more thorough explanations.

In any further problems, when rounding is mentioned - just the same rounding algorithm is supposed (unless other is explicitly specified).

Example:

data:
3
12 8
11 -3
400 5

result:
2 -4 80
You need to login to get test data and submit solution.