human
What is a code to reverse an array without using subtract sign â €˜ and the other steps required given the following:
Reverse an array without using subtract sign â €˜ | Function to reverse array.
Reverse array in simple manner.
Swap ith index value with ( n - i - 1 ) th index value Note : A - B = A + ~ B + 1 So n - i = n + ~ i + 1 then n - i - 1 = ( n + ~ i + 1 ) + ~ 1 + 1.
Driver code.
print the reversed array"
Solution in Python:
assistant
#Here is code to reverse an array without using subtract sign â €˜ and the other steps required.
 def reverseArray ( arr , n ) :
	for i in range ( n // 2 ) :
		arr [ i ] , arr [ ( n + ~ i + 1 ) + ~ 1 + 1 ] = arr [ ( n + ~ i + 1 ) + ~ 1 + 1 ] , arr [ i ]
arr = [ 5 , 3 , 7 , 2 , 1 , 6 ]
n = len ( arr )
reverseArray ( arr , n )
for i in range ( n ) :
	print ( arr [ i ] , end = " ▁ " )