Find nth Hermite number | Utility function to calculate double factorial of a number ; Function to return nth Hermite number ; If n is even then return 0 ; If n is odd ; Calculate double factorial of ( n - 1 ) and multiply it with 2 ^ ( n / 2 ) ; If n / 2 is odd then nth Hermite number will be negative ; Return nth Hermite number ; Driver Code ; Print nth Hermite number
< ? php function doubleFactorial ( $ n ) { $ fact = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i = $ i + 2 ) { $ fact = $ fact * $ i ; } return $ fact ; } function hermiteNumber ( $ n ) { if ( $ n % 2 == 1 ) return 0 ; else { $ number = ( pow ( 2 , $ n / 2 ) ) * doubleFactorial ( $ n - 1 ) ; if ( ( $ n / 2 ) % 2 == 1 ) $ number = $ number * -1 ; return $ number ; } } $ n = 6 ; echo hermiteNumber ( $ n ) ; ? >