Find the sum of the first N Centered Octagonal Number | Function to find the N - th centered octagonal number ; Formula to calculate nth centered octagonal number ; Function to find the sum of the first N centered octagonal numbers ; Variable to store the sum ; Iterating through the range 1 to N ; Driver code
function center_Octagonal_num ( n ) { return ( 4 * n * n - 4 * n + 1 ) ; } function sum_center_Octagonal_num ( n ) { let summ = 0 ; for ( let i = 1 ; i < n + 1 ; i ++ ) { summ += center_Octagonal_num ( i ) ; } return summ ; } let n = 5 ; document . write ( sum_center_Octagonal_num ( n ) ) ;