ITPEC FE Subject B April 2025 Question 14

From the answer group below, select the correct combination of answers to be inserted into A and B in the program.

The function cosine(z) returns an approximate value of the cosine value of z degrees. The function uses Maclaurin series expansion for the cosine shown below and can be used to determine cos(y) for values of y radians.

cos(y) = 1 − y22! + y44! − y66! + ⋯

[Program]
○ real: cosine(real: z)
real: y ← z × π ÷ 180 // convert from degrees to radians
real: term ← 1
real: cosy ← term
integer: n ← 0
while (absolute value of A > 0.000000001)
n ← n + 1
term ← term × (-1 × (y B) ÷ (2 × n × (2 × n - 1)))
cosy ← cosy + term
endwhile
return cosy

Answer group

OptionAB

Explanation

A: term and B: squared — each series term is the previous one times -y2 ÷ (2n(2n - 1)), and the loop stops once the latest term is negligible.

The n-th term of the series is (-1)n y2n ÷ (2n)!. Dividing it by term n − 1 leaves -y2 ÷ (2n(2n - 1)): one more factor y2 and two more factorial factors. Tracing the program with B = squared, starting from term = 1:

  • •n = 1: 1 × (-y2) ÷ (2 × 1) = -y2 ÷ 2!
  • •n = 2: (-y2 ÷ 2) × (-y2) ÷ (4 × 3) = y4 ÷ 4!
  • •n = 3: (y4 ÷ 24) × (-y2) ÷ (6 × 5) = -y6 ÷ 6!

Blank A is the stopping test. The factorial outgrows the power, so the terms shrink toward 0; once the absolute value of term is no more than 0.000000001, further terms no longer change cosy meaningfully.

Answer (f)

Why not others:

  • •(a), (b) and (c) — A = cosy tests the running total, which approaches cos(y), not 0; for most angles it never falls below the threshold, so the loop never ends
  • •(d) — y to the power 2n multiplies in too much, because term already carries y2(n-1): at n = 2 it produces a y6 term where y4 belongs
  • •(e) — y to the power 4 is wrong from the first step: n = 1 gives -y4 ÷ 2 instead of -y2 ÷ 2

Key rule: In an iterative series, update the term by the ratio between consecutive terms instead of recomputing powers, and stop on the size of the latest term, not of the sum.

Math & Numbers · 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.