Check if it is possible to move from ( 0 , 0 ) to ( X , Y ) in exactly K steps | C ++ implementation of the approach ; Function that returns true if it is possible to move from ( 0 , 0 ) to ( x , y ) in exactly k moves ; Minimum moves required ; If possible ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPossible ( int x , int y , int k ) { int minMoves = abs ( x ) + abs ( y ) ; if ( k >= minMoves && ( k - minMoves ) % 2 == 0 ) return true ; return false ; } int main ( ) { int x = 5 , y = 8 , k = 20 ; if ( isPossible ( x , y , k ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }