Find sum of factorials in an array | Java implementation of the approach ; 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
class GFG { static int factorial ( int n ) { int f = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { f *= i ; } return f ; } static int sumFactorial ( int [ ] arr , int n ) { int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += factorial ( arr [ i ] ) ; } return s ; } public static void main ( String [ ] args ) { int [ ] arr = { 7 , 3 , 5 , 4 , 8 } ; int n = arr . length ; System . out . println ( sumFactorial ( arr , n ) ) ; } }