Pentagonal Pyramidal Number | function to get nth Pentagonal pyramidal number . ; Running loop from 1 to n ; get nth pentagonal number ; add to sum ; Driver Code
< ? php function pentagon_pyramidal ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ p = ( 3 * $ i * $ i - $ i ) / 2 ; $ sum = $ sum + $ p ; } return $ sum ; } $ n = 4 ; echo pentagon_pyramidal ( $ n ) ; ? >