Iterative double factorial

Write an iterative function that returns the double factorial @n@!! for
a natural n.

Recall that n!! = n × (n − 2) × (n − 4) × …. For instance,
9!! = 9 × 7 × 5 × 3 × 1 = 945 and 8!! = 8 × 6 × 4 × 2 = 384. By
definition, 0!! = 1!! = 1.

Interface

+-------:+:----------------------------------------------+
| C++,C  |     int double_factorial(int x);              |
+--------+-----------------------------------------------+
| Java   |     public static int doubleFactorial(int x); |
+--------+-----------------------------------------------+
| Python |     double_factorial(x)  # returns int        |
+--------+-----------------------------------------------+
|        |     double_factorial(x: int) -> int           |
+--------+-----------------------------------------------+

Precondition

Assume 0≤ @n@  ≤ 19.

Observation

You only need to submit the required procedure; your main program will
be ignored.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:19:33.423Z

© Jutge.org, 2006–2026.
https://jutge.org
