Find the sum of the first N Centered Pentagonal Number | Function to find the Centered_Pentagonal number ; Formula to calculate nth Centered_Pentagonal number & return it into main function . ; Function to find the sum of the first N Centered_Pentagonal numbers ; To get the sum ; Iterating through the range 1 to N ; Driver code ; Display first Nth Centered_Pentagonal number
function Centered_Pentagonal_num ( n ) { return ( 5 * n * n - 5 * n + 2 ) / 2 ; } function sum_Centered_Pentagonal_num ( n ) { let summ = 0 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Pentagonal_num ( i ) ; } return summ ; } let n = 5 ; document . write ( sum_Centered_Pentagonal_num ( n ) ) ;