Prefix Factorials of a Prefix Sum Array | Function to find the factorial of a number N ; Base Case ; Find the factorial recursively ; Function to find the prefix factorial array ; Find the prefix sum array ; Find the factorials of each array element ; Print the resultant array ; Driver Code
function fact ( N ) { if ( N == 1 N == 0 ) return 1 ; return N * fact ( N - 1 ) ; } function prefixFactorialArray ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; } for ( let i = 0 ; i < N ; i ++ ) { arr [ i ] = fact ( arr [ i ] ) ; } for ( let i = 0 ; i < N ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } let arr = [ 1 , 2 , 3 , 4 ] ; let N = arr . length ; prefixFactorialArray ( arr , N ) ;