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
function doubleFactorial ( n ) { var fact = 1 ; for ( var i = 1 ; i <= n ; i = i + 2 ) { fact = fact * i ; } return fact ; } function hermiteNumber ( n ) { if ( n % 2 == 1 ) return 0 ; else { var number = ( Math . pow ( 2 , n / 2 ) ) * doubleFactorial ( n - 1 ) ; if ( ( n / 2 ) % 2 == 1 ) number = number * - 1 ; return number ; } } var n = 6 ; document . write ( hermiteNumber ( n ) ) ;