Pentanacci Numbers | Function to print Nth Pentanacci number ; Initialize first five numbers to base cases ; Declare a current variable ; Loop to add previous five numbers for each number starting from 5 and then assign first , second , third , fourth to second , third , fourth and curr to fifth respectively ; Driver code
function printpenta ( n ) { if ( n < 0 ) return ; let first = 0 ; let second = 0 ; let third = 0 ; let fourth = 0 ; let fifth = 1 ; let curr = 0 ; if ( n == 0 n == 1 n == 2 n == 3 ) document . write ( first + " " ) ; else if ( n == 5 ) document . write ( fifth + " " ) ; else { for ( let i = 5 ; i < n ; i ++ ) { curr = first + second + third + fourth + fifth ; first = second ; second = third ; third = fourth ; fourth = fifth ; fifth = curr ; } document . write ( curr + " " ) ; } } let n = 10 ; printpenta ( n ) ;