Reduce all array elements to zero by performing given operations thrice | Function to reduce all array elements to zero ; If size of array is 1 ; First operation ; 2 nd Operation ; 3 rd Operation ; Otherwise ; 1 st Operation ; 2 nd Operation ; 3 rd Operation ; Driver Code ; Input ; Function call to make all array elements equal to 0
def ConvertArray ( arr , N ) : NEW_LINE INDENT if ( N == 1 ) : NEW_LINE INDENT print ( " Operation ▁ 1 ▁ : " , 1 , 1 ) NEW_LINE print ( " Added ▁ elements : " , - 1 * arr [ 0 ] ) NEW_LINE print ( " " , end ▁ = ▁ " " ) NEW_LINE print ( " Operation ▁ 2 ▁ : " , 1 , 1 ) NEW_LINE print ( " Added ▁ elements : " , 1 * arr [ 0 ] ) NEW_LINE print ( " " , end ▁ = ▁ " " ) NEW_LINE print ( " Operation ▁ 3 ▁ : " , 1 , 1 ) NEW_LINE print ( " Added ▁ elements : " , - 1 * arr [ 0 ] ) NEW_LINE print ( " " , end ▁ = ▁ " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Operation ▁ 1 ▁ : " , 1 , N ) NEW_LINE print ( " Added ▁ elements : " , end = " ▁ " ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT print ( - 1 * arr [ i ] * N , end = " ▁ " ) NEW_LINE DEDENT print ( " " ) NEW_LINE print ( " Operation ▁ 2 ▁ : " , 1 , N - 1 ) NEW_LINE print ( " Added ▁ elements : " , end = " ▁ " ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT print ( arr [ i ] * ( N - 1 ) , end = " ▁ " ) NEW_LINE DEDENT print ( " " ) NEW_LINE print ( " Operation ▁ 3 ▁ : ▁ " , N , N ) NEW_LINE print ( " Added ▁ elements : " , end = " ▁ " ) NEW_LINE print ( arr [ N - 1 ] * ( N - 1 ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 3 , 2 , 4 ] NEW_LINE N = len ( arr ) NEW_LINE ConvertArray ( arr , N ) NEW_LINE DEDENT