ITPEC FE Subject B October 2024 Question 5
From the answer group below, select the correct combination of answers to be inserted into A and B in the program. Here, the array index starts at 1.
Function calcGeoMean receives the array dataArray (the number of elements ≥ 1) as an argument and returns the geometric mean of values in dataArray as the return value. For the numbers a1, a2, …, an, the geometric mean is n√(a1 × a2 × ⋯ × an). Here, the pow( function returns a real value by raising x to the power of y. In the program, division is performed in data type real.
Answer group
Explanation
A: product, B: 1 ÷ n — the n-th root of the product is the product raised to the power 1 ÷ n.
The loop leaves a1 × a2 × ⋯ × an in product. Since pow( computes xy, and n√x = x1/n, the base is product and the exponent is 1 ÷ n. The question states that division is done in real, so the exponent is not truncated to 0.
Check with {2, 8}: product is 16 and n is 2, so the result is 160.5 = 4, and indeed 2 × 8 = 4 × 4.
Answer (b)
Why not others:
- •(a) — base and exponent are swapped: (1 ÷ n)product, which for the example is 0.516, about 0.000015
- •(c) — raises the product to the n-th power instead of taking the n-th root: 162 = 256
- •(d) — gets both arguments wrong: nproduct = 216 = 65,536
Key rule: A k-th root is the power 1 ÷ k; the exponent must be computed in real arithmetic, since integer division would turn it into 0.
Math & Data Science · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.