human
Give me a code to reduce all array elements to zero by performing given operations thrice and the other steps required given the following:
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"
Solution in Python:
assistant
#Here is code to reduce all array elements to zero by performing given operations thrice and the other steps required.
 def ConvertArray ( arr , N ) :
	if ( N == 1 ) :
		print ( " Operation ▁ 1 ▁ : " , 1 , 1 )
		print ( " Added ▁ elements : " , - 1 * arr [ 0 ] )
		print ( " " , end ▁ = ▁ " " )
		print ( " Operation ▁ 2 ▁ : " , 1 , 1 )
		print ( " Added ▁ elements : " , 1 * arr [ 0 ] )
		print ( " " , end ▁ = ▁ " " )
		print ( " Operation ▁ 3 ▁ : " , 1 , 1 )
		print ( " Added ▁ elements : " , - 1 * arr [ 0 ] )
		print ( " " , end ▁ = ▁ " " )
	else :
		print ( " Operation ▁ 1 ▁ : " , 1 , N )
		print ( " Added ▁ elements : " , end = " ▁ " )
		for i in range ( N ) :
			print ( - 1 * arr [ i ] * N , end = " ▁ " )
		print ( " " )
		print ( " Operation ▁ 2 ▁ : " , 1 , N - 1 )
		print ( " Added ▁ elements : " , end = " ▁ " )
		for i in range ( N - 1 ) :
			print ( arr [ i ] * ( N - 1 ) , end = " ▁ " )
		print ( " " )
		print ( " Operation ▁ 3 ▁ : ▁ " , N , N )
		print ( " Added ▁ elements : " , end = " ▁ " )
		print ( arr [ N - 1 ] * ( N - 1 ) )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 3 , 2 , 4 ]
	N = len ( arr )
	ConvertArray ( arr , N )