Iterative double factorial

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

Recall that n!!=n×(n2)×(n4)×n!! = n \times (n - 2) \times (n - 4) \times \dots. For instance, 9!!=9×7×5×3×1=9459!! = 9 \times 7 \times 5 \times 3 \times 1 = 945 and 8!!=8×6×4×2=3848!! = 8 \times 6 \times 4 \times 2 = 384. By definition, 0!!=1!!=10!! = 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 00\le @n@ 19\le 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