Program to print pentatope numbers upto Nth term | Function to generate nth tetrahedral number ; Function to print pentatope number series upto nth term . ; Initialize prev as 0. It store the sum of all previously generated pentatope numbers ; Loop to print pentatope series ; Find ith tetrahedral number ; Add ith tetrahedral number to sum of all previously generated tetrahedral number to get ith pentatope number ; Update sum of all previously generated tetrahedral number ; Driver code ; Function call to print pentatope number series
function findTetrahedralNumber ( n ) { return ( ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ) ; } function printSeries ( n ) { let prev = 0 ; let curr ; for ( let i = 1 ; i <= n ; i ++ ) { curr = findTetrahedralNumber ( i ) ; curr = curr + prev ; document . write ( curr + " " ) ; prev = curr ; } } let n = 10 ; printSeries ( n ) ;