Find the sum of the first half and second half elements of an array | Function to find the sum of the first half elements and second half elements of an array ; Add elements in first half sum ; Add elements in the second half sum ; Driver Code ; Function call
def sum_of_elements ( arr , n ) : NEW_LINE INDENT sumfirst = 0 ; NEW_LINE sumsecond = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i < n // 2 ) : NEW_LINE INDENT sumfirst += arr [ i ] ; NEW_LINE DEDENT else : NEW_LINE INDENT sumsecond += arr [ i ] ; NEW_LINE DEDENT DEDENT print ( " Sum ▁ of ▁ first ▁ half ▁ elements ▁ is " , sumfirst , end =   " " ) ; NEW_LINE print ( " Sum ▁ of ▁ second ▁ half ▁ elements ▁ is " , sumsecond , end =   " " ) ; NEW_LINE DEDENT arr = [ 20 , 30 , 60 , 10 , 25 , 15 , 40 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE sum_of_elements ( arr , n ) ; NEW_LINE