Sum of all elements in an array between zeros | Function to find the sum between two zeros in the given array arr [ ] ; To store the sum of the element between two zeros ; To store the sum ; Find first index of 0 ; Traverse the given array arr [ ] ; If 0 occurs then add it to A [ ] ; Else add element to the sum ; Print all the sum stored in A ; If there is no such element print - 1 ; Driver Code ; Function call
def sumBetweenZero ( arr , N ) : NEW_LINE INDENT i = 0 NEW_LINE A = [ ] NEW_LINE sum = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT i += 1 NEW_LINE break NEW_LINE DEDENT DEDENT k = i NEW_LINE for i in range ( k , N , 1 ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT A . append ( sum ) NEW_LINE sum = 0 NEW_LINE DEDENT else : NEW_LINE INDENT sum += arr [ i ] NEW_LINE DEDENT DEDENT for i in range ( len ( A ) ) : NEW_LINE INDENT print ( A [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT if ( len ( A ) == 0 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 0 , 3 , 4 , 0 , 4 , 4 , 0 , 2 , 1 , 4 , 0 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE sumBetweenZero ( arr , N ) NEW_LINE DEDENT