191k views
5 votes
Given 3 integers, output their average and their product, using integer arithmetic.

Ex: If the input is:

10 20 5
the output is:

11 1000

User Daevin
by
7.6k points

1 Answer

6 votes

Final answer:

To find the average and product of three integers in integer arithmetic, add them together and divide by 3 for the average, and multiply them together for the product. The average of 10, 20, and 5 is 11, and the product is 1000.

Step-by-step explanation:

To calculate the average of three integers using integer arithmetic, you need to add the integers together and then divide by 3.

For the product, you would multiply the three numbers together. However, with integer arithmetic, division results in an integer as well, which means any fractional part will be truncated. It is important to do the division last to not lose precision in the process.

Let's use the example given: with the numbers 10, 20, and 5. First, calculate their sum: 10 + 20 + 5 = 35.

Next, divide this sum by 3 to get the average: 35 / 3 which equals 11 when using integer arithmetic because the fractional part (.666) is discarded.

To get the product, multiply the numbers together: 10 * 20 * 5 = 1000.

So, the average is 11 and the product is 1000.

User Dan Mertz
by
8.2k points