TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Compute double factorial: \(n!!\). More...
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
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!!\)
Definition in file double_factorial.cpp.
uint64_t double_factorial_iterative | ( | uint64_t | n | ) |
Compute double factorial using iterative method
Definition at line 18 of file double_factorial.cpp.
uint64_t double_factorial_recursive | ( | uint64_t | n | ) |
Compute double factorial using resursive method.
Recursion can be costly for large numbers.
Definition at line 31 of file double_factorial.cpp.
int main | ( | void | ) |
Main function
Definition at line 68 of file double_factorial.cpp.
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 |
Definition at line 43 of file double_factorial.cpp.
void tests | ( | ) |
Test implementations
Definition at line 51 of file double_factorial.cpp.