Program to check if N is a Pentagonal Number | Function to determine if N is pentagonal or not . ; Substitute values of i in the formula . ; Driver code
function isPentagonal ( N ) { var i = 1 , M ; do { M = ( 3 * i * i - i ) / 2 ; i += 1 ; } while ( M < N ) ; return ( M == N ) ; } var N = 12 ; if ( isPentagonal ( N ) ) document . write ( N + " " ) ; else document . write ( N + " " ) ;