text: Minimum number of steps required to reach origin from a given point | C # program for the above approach ; Function to find the minimum moves required to reach origin from ( a , b ) ; Stores the minimum number of moves ; Check if the absolute difference is 1 or 0 ; Store the minimum of a , b ; Store the maximum of a , b ; Print the answer ; Driver Code ; Given co - ordinates ; Function Call
code: using System ; class GFG { static void findMinMoves ( int a , int b ) { int ans = 0 ; if ( a == b || Math . Abs ( a - b ) == 1 ) { ans = a + b ; } else { int k = Math . Min ( a , b ) ; int j = Math . Max ( a , b ) ; ans = 2 * k + 2 * ( j - k ) - 1 ; } Console . Write ( ans ) ; } public static void Main ( ) { int a = 3 , b = 5 ; findMinMoves ( a , b ) ; } }