Multiplication

Problem #5

Tags: computing instructional

Who solved this?

Previous:Addition II Next:Division


Now let's take a look at the operation of multiplication, in which we take two numbers called the multiplicands a and b, and then adding a to itself b times to yield the product. Geometrically, this is equivalent of finding the area of a rectangle with side lengths a and b.

Addition

Just like addition, multiplcation is also commutative (a * b = b * a) and associative ((a * b) * c = a * (b * c).

To mulitply two values together, we write the multiplicands a over b and align their rightmost digits. Then starting at the rightmost digit of b, we multiply that digit by each digit in a from right to left, writing the sub-product below such that its rightmost digit is aligned with the current digit of b. If the sub-product is 10 or greater, then only the "ones" digit is written below and the remaining digits are added to the next column instead. Once all the digits of b have been exhausted, sum up all of the sub-products, and place a decimal point such that the decimal places of the total product is equal to the sum of the decimal places of all multiplicands.

For example to multiply together the numbers 12.3 and 4.56...

       1 2.3
    x  4.5 6
    --------
       7 3 8
     6 1 5
+  4 9 2
------------
   5 6.0 8 8

Problem Statement

You will be given several numbers. Multiply them together and return the product.

Input Data
First line will be Q, the quantity of multiplicands.
Q lines will then follow, each with a single multiplicand.

Answer
Should consist of a single value, being the product of all given addends.
Do not round nor truncate any significant digits in answer.
Remove any trailing zeroes in final answer.

Example

input data:
5
1.2
3.4
5.6
7.8
9.0

answer:
1603.9296
You need to login to get test data and submit solution.