Find the final X and Y when they are Altering under given condition | CPP tp implement above approach ; Function to get final value of X and Y ; Following the sequence but by replacing minus with modulo ; Step 1 ; Step 2 ; Step 3 ; Otherwise terminate ; Driver function ; Get the initial X and Y values ; Find the result
#include <iostream> NEW_LINE using namespace std ; void alter ( long long int x , long long int y ) { while ( true ) { if ( x == 0 y == 0 ) break ; if ( x >= 2 * y ) x = x % ( 2 * y ) ; else if ( y >= 2 * x ) y = y % ( 2 * x ) ; else break ; } cout << " X = " << x << " , ▁ " << " Y = " << y ; } int main ( ) { long long int x = 12 , y = 5 ; alter ( x , y ) ; return 0 ; }