IPA FE Subject B sample Question 5
A question IPA Japan published in 基本情報技術者試験 科目B サンプル問題 問5, translated into English. ITPEC is based on the same exams.
From the answer group below, select the correct answer to be inserted into blank in the program.
The function calc receives the positive real numbers x and y, and returns the result of the calculation of √x2 + y2. The function pow, which is used by the function calc, receives a positive real number a as the first argument and a real number b as the second argument, and returns the value of a raised to the power of b as a real-type value.
Answer group
Explanation
pow(pow(x, 2) + pow(y, 2), 0.5) — a square is the power 2 and a square root is the power 0.5, so build x2 + y2 first and raise the whole sum to 0.5.
√x2 + y2 = (x2 + y2)0.5. The inner calls pow( and pow( give the squares, their sum is the first argument of the outer pow, and 0.5 is its exponent. Check with calc(: 9 + 16 = 25, and 250.5 = 5. The values below are for the same call.
Answer (e)
Why not others:
- •(a) — divides the sum of squares by √2 instead of taking its root: 25 ÷ 1.414, about 17.7
- •(b) — divides the sum of squares by xy = 81: about 0.31
- •(c) — 2√x + 2√y, the roots used as exponents of 2: about 7.32
- •(d) — ((2x)y)0.5 = 2xy ÷ 2 = 26 = 64
- •(f) — x2 × y2 ÷ xy = 144 ÷ 81, about 1.78
- •(g) — xy ÷ √2 = 81 ÷ 1.414, about 57.3
Key rule: A root is a fractional power, √v = v0.5 and the n-th root is v1/n; apply it to the whole expression under the radical sign, as the outermost call.
Math & Numbers · AI-written, may contain errors
This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.