bug fix - no function return and invalid for loop termination check

This commit is contained in:
Krishna Vedala 2020-05-27 12:54:42 -04:00
parent 4134c16f42
commit 44f68e9a2e
No known key found for this signature in database
GPG Key ID: BA19ACF8FC8792F7

View File

@ -11,10 +11,11 @@
/// Compute double factorial using iterative method
uint64_t double_factorial_iterative(uint64_t n) {
uint64_t res = 1;
for (uint64_t i = n; i >= 0; i -= 2) {
for (uint64_t i = n;; i -= 2) {
if (i == 0 || i == 1) return res;
res *= i;
}
return res;
}
/// Compute double factorial using resursive method.