Find initial integral solution of Linear Diophantine equation if finite solution exists | Javascript program for the above approach ; Function to implement the extended euclid algorithm ; Base Case ; Recursively find the gcd ; Function to prlet the solutions of the given equations ax + by = c ; Condition for infinite solutions ; Condition for no solutions exist ; Condition for no solutions exist ; Print the solution ; Driver Code ; Given coefficients ; Function Call
let x , y ; function gcd_extend ( a , b ) { if ( b == 0 ) { x = 1 ; y = 0 ; return a ; } else { let g = gcd_extend ( b , a % b ) ; let x1 = x , y1 = y ; x = y1 ; y = x1 - Math . floor ( a / b ) * y1 ; return g ; } } function print_solution ( a , b , c ) { if ( a == 0 && b == 0 ) { if ( c == 0 ) { document . write ( " " + " " + " " ) ; } else { document . write ( " " + " " ) ; } } let gcd = gcd_extend ( a , b ) ; if ( c % gcd != 0 ) { document . write ( " " + " " ) ; } else { document . write ( " " + x * ( c / gcd ) + " " + y * ( c / gcd ) + " " ) ; } } let a , b , c ; a = 4 ; b = 18 ; c = 10 ; print_solution ( a , b , c ) ;