Solution - part II

The task does not specify special string formatting or rounding the result, therefore, we just have to calculate the output and print it on the console.

Let' s pay attention to something that applies to all other problems of this type: written like that, the solution of the task is pretty detailed. As the task itself is not too complex, in theory, we could write one big expression, where right after having received the input, we calculate the output. For example, such expression would look like this:

This code would print a correct result, but it is hard to read. It won't be easy to find out how it works and whether it contains any mistakes, as well as finding one and correcting it. Instead of one complex expression, it is better to write a few simpler ones and store their values in variables with appropriate names. This way, the code is more clean and easily maintainable.

Test in the Judge system

Test your solution here:

results matching ""

    No results matching ""