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
< ? php function isPentagonal ( int $ N ) { $ i = 1 ; $ M ; do { $ M = ( 3 * $ i * $ i - $ i ) / 2 ; $ i += 1 ; } while ( $ M < $ N ) ; return ( $ M == $ N ) ; } $ N = 12 ; if ( isPentagonal ( $ N ) ) echo $ N , " ▁ is ▁ pentagonal ▁ " ; else echo $ N , " ▁ is ▁ not ▁ pentagonal " ; ? >