Check if possible to move from given coordinate to desired coordinate | C # program to check if it is possible to reach ( a , b ) from ( x , y ) . ; Returns GCD of i and j ; Returns true if it is possible to go to ( a , b ) from ( x , y ) ; Find absolute values of all as sign doesn 't matter. ; If gcd is equal then it is possible to reach . Else not possible . ; Driver code ; Converting coordinate into positive integer
using System ; class GFG { static int gcd ( int i , int j ) { if ( i == j ) return i ; if ( i > j ) return gcd ( i - j , j ) ; return gcd ( i , j - i ) ; } static bool ispossible ( int x , int y , int a , int b ) { x = Math . Abs ( x ) ; y = Math . Abs ( y ) ; a = Math . Abs ( a ) ; b = Math . Abs ( b ) ; return ( gcd ( x , y ) == gcd ( a , b ) ) ; } public static void Main ( ) { int x = 35 , y = 15 ; int a = 20 , b = 25 ; if ( ispossible ( x , y , a , b ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }