Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Compute double factorial: \(n!!\). More...
#include <cassert>
#include <iostream>
Functions | |
uint64_t | double_factorial_iterative (uint64_t n) |
uint64_t | double_factorial_recursive (uint64_t n) |
void | test (uint64_t n, uint64_t expected) |
void | tests () |
int | main () |
Compute double factorial: \(n!!\).
Double factorial of a non-negative integer n
, is defined as the product of all the integers from 1 to n that have the same parity (odd or even) as n.
It is also called as semifactorial of a number and is denoted by \(n!!\)
uint64_t double_factorial_iterative | ( | uint64_t | n | ) |
Compute double factorial using iterative method
uint64_t double_factorial_recursive | ( | uint64_t | n | ) |
Compute double factorial using resursive method.
Recursion can be costly for large numbers.
int main | ( | void | ) |
void test | ( | uint64_t | n, |
uint64_t | expected ) |
Wrapper to run tests using both recursive and iterative implementations. The checks are only valid in debug builds due to the use of assert()
statements.
[in] | n | number to check double factorial for |
[in] | expected | expected result |