Reverse an array without using subtract sign â €˜ | C # program to reverse an array without using " - " sign ; Function to reverse array ; Trick to assign - 1 to a variable ; Reverse array in simple manner ; Swap ith index value with ( n - i - 1 ) th index value ; Drivers code ; print the reversed array
using System ; class GFG { static void reverseArray ( int [ ] arr , int n ) { int x = ( int . MinValue / int . MaxValue ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) swap ( arr , i , n + ( x * i ) + x ) ; } static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } public static void Main ( ) { int [ ] arr = { 5 , 3 , 7 , 2 , 1 , 6 } ; int n = arr . Length ; reverseArray ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }