#! /usr/bin/env python3 # def double_factorial ( n ): #*****************************************************************************80 # ## double_factorial() evaluates the double factorial function. # # Discussion: # # The double factorial function of n is represented by n!! # # If n is even, n!! = 2 * 4 * ... * n-2 * n # # If n is odd, n!! = 1 * 3 * ... * n-2 * n # # Modified: # # 17 January 2023 # # Author: # # John Burkardt # # Input: # # integer n: the argument. # # Output: # # integer value: the value of n!! # value = 1 while ( 0 < n ): value = value * n n = n - 2 return value def double_factorial_test ( ): #*****************************************************************************80 # ## double_factorial() evaluates the double factorial function. # exact = [ 1, 1, 2, 3, 8, 15, 48, 105, 384, 945, 3840, 10395, 46080, 125135, 645120 ] exact_num = len ( exact ) print ( '' ) print ( 'double_factorial_test():' ) print ( ' Test double_factorial(n)' ) print ( '' ) for n in range ( 0, exact_num ): value = double_factorial ( n ) print ( n, value, exact[n] ) return if ( __name__ == "__main__" ): double_factorial_test ( )