TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
z
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
z
Variables
Typedefs
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
~
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Variables
_
a
b
c
d
e
f
g
h
i
k
l
m
n
p
q
r
s
t
u
v
w
x
y
Typedefs
Related Symbols
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
w
z
Functions
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
z
Variables
Typedefs
Macros
Examples
▼
TheAlgorithms/C++
►
The Algorithms - C++
►
Contributor Covenant Code of Conduct
►
Code style convention
►
CONTRIBUTION GUIDELINES
►
Backtracking
Prime factorization
Guidelines for reviewers and maintainers
Todo List
►
Topics
►
Namespaces
►
Classes
▼
Files
▼
File List
►
backtracking
►
bit_manipulation
►
ciphers
►
cpu_scheduling_algorithms
►
data_structures
►
divide_and_conquer
►
dynamic_programming
►
games
►
geometry
►
graph
►
graphics
►
greedy_algorithms
►
hashing
►
machine_learning
▼
math
►
aliquot_sum.cpp
►
approximate_pi.cpp
►
area.cpp
armstrong_number.cpp
►
binary_exponent.cpp
►
binomial_calculate.cpp
►
check_amicable_pair.cpp
►
check_factorial.cpp
►
check_prime.cpp
►
complex_numbers.cpp
►
double_factorial.cpp
►
eratosthenes.cpp
►
eulers_totient_function.cpp
►
extended_euclid_algorithm.cpp
►
factorial.cpp
►
fast_power.cpp
►
fibonacci.cpp
►
fibonacci_fast.cpp
►
fibonacci_large.cpp
►
fibonacci_matrix_exponentiation.cpp
►
fibonacci_sum.cpp
►
finding_number_of_digits_in_a_number.cpp
►
gcd_iterative_euclidean.cpp
►
gcd_of_n_numbers.cpp
►
gcd_recursive_euclidean.cpp
►
integral_approximation.cpp
►
integral_approximation2.cpp
►
inv_sqrt.cpp
►
iterative_factorial.cpp
►
large_factorial.cpp
►
large_number.h
►
largest_power.cpp
►
lcm_sum.cpp
►
least_common_multiple.cpp
linear_recurrence_matrix.cpp
►
magic_number.cpp
►
miller_rabin.cpp
►
modular_division.cpp
►
modular_exponentiation.cpp
►
modular_inverse_fermat_little_theorem.cpp
►
modular_inverse_simple.cpp
►
n_bonacci.cpp
►
n_choose_r.cpp
►
ncr_modulo_p.cpp
►
number_of_positive_divisors.cpp
►
perimeter.cpp
►
power_for_huge_numbers.cpp
►
power_of_two.cpp
►
prime_factorization.cpp
►
prime_numbers.cpp
►
primes_up_to_billion.cpp
►
quadratic_equations_complex_numbers.cpp
►
realtime_stats.cpp
►
sieve_of_eratosthenes.cpp
►
sqrt_double.cpp
►
string_fibonacci.cpp
►
sum_of_binomial_coefficient.cpp
►
sum_of_digits.cpp
►
vector_cross_product.cpp
►
volume.cpp
►
numerical_methods
►
operations_on_datastructures
►
others
►
physics
►
probability
►
range_queries
►
scripts
►
search
►
sorting
►
strings
►
File Members
►
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
double_factorial.cpp
Go to the documentation of this file.
1
12
#include <cassert>
13
#include <cstdint>
14
#include <iostream>
15
18
uint64_t
double_factorial_iterative
(uint64_t n) {
19
uint64_t res = 1;
20
for
(uint64_t i = n;; i -= 2) {
21
if
(i == 0 || i == 1)
22
return
res;
23
res *= i;
24
}
25
return
res;
26
}
18
uint64_t
double_factorial_iterative
(uint64_t n) {
…
}
27
31
uint64_t
double_factorial_recursive
(uint64_t n) {
32
if
(n <= 1)
33
return
1;
34
return
n *
double_factorial_recursive
(n - 2);
35
}
31
uint64_t
double_factorial_recursive
(uint64_t n) {
…
}
36
43
void
test
(uint64_t n, uint64_t expected) {
44
assert(
double_factorial_iterative
(n) == expected);
45
assert(
double_factorial_recursive
(n) == expected);
46
}
43
void
test
(uint64_t n, uint64_t expected) {
…
}
47
51
void
tests
() {
52
std::cout <<
"Test 1:\t n=5\t..."
;
53
test
(5, 15);
54
std::cout <<
"passed\n"
;
55
56
std::cout <<
"Test 2:\t n=15\t..."
;
57
test
(15, 2027025);
58
std::cout <<
"passed\n"
;
59
60
std::cout <<
"Test 3:\t n=0\t..."
;
61
test
(0, 1);
62
std::cout <<
"passed\n"
;
63
}
51
void
tests
() {
…
}
64
68
int
main
() {
69
tests
();
70
return
0;
71
}
68
int
main
() {
…
}
double_factorial_iterative
uint64_t double_factorial_iterative(uint64_t n)
Definition
double_factorial.cpp:18
double_factorial_recursive
uint64_t double_factorial_recursive(uint64_t n)
Definition
double_factorial.cpp:31
tests
void tests()
Definition
double_factorial.cpp:51
main
int main()
Definition
double_factorial.cpp:68
test
static void test()
Self-test implementations.
Definition
generate_parentheses.cpp:82
math
double_factorial.cpp
Generated by
1.12.0