Find sum of factorials in an array | Function to return the factorial of n ; Function to return the sum of factorials of the array elements ; To store the required sum ; Add factorial of all the elements ; Driver code
def factorial ( n ) : NEW_LINE INDENT f = 1 ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT f *= i ; NEW_LINE DEDENT return f ; NEW_LINE DEDENT def sumFactorial ( arr , n ) : NEW_LINE INDENT s = 0 ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT s += factorial ( arr [ i ] ) ; NEW_LINE DEDENT return s ; NEW_LINE DEDENT arr = [ 7 , 3 , 5 , 4 , 8 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( sumFactorial ( arr , n ) ) ; NEW_LINE