Find the missing digit in given product of large positive integers | Function to find the replaced digit in the product of a * b ; Keeps track of the sign of the current digit ; Stores the value of a % 11 ; Find the value of a mod 11 for large value of a as per the derived formula ; Stores the value of b % 11 ; Find the value of b mod 11 for large value of a as per the derived formula ; Stores the value of c % 11 ; Keeps track of the sign of x ; If the current digit is the missing digit , then keep the track of its sign ; Find the value of x using the derived equation ; Check if x has a negative sign ; Return positive equivaluent of x mod 11 ; Driver Code
function findMissingDigit ( a , b , c ) { let w = 1 ; let a_mod_11 = 0 ; for ( let i = a . length - 1 ; i >= 0 ; i -- ) { a_mod_11 = ( a_mod_11 + w * ( a [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) % 11 ; w = w * - 1 ; } let b_mod_11 = 0 ; w = 1 ; for ( let i = b . length - 1 ; i >= 0 ; i -- ) { b_mod_11 = ( b_mod_11 + w * ( b [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) % 11 ; w = w * - 1 ; } let c_mod_11 = 0 ; let xSignIsPositive = true ; w = 1 ; for ( let i = c . length - 1 ; i >= 0 ; i -- ) { if ( c [ i ] == ' ' ) { xSignIsPositive = ( w == 1 ) ; } else { c_mod_11 = ( c_mod_11 + w * ( c [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) ) % 11 ; } w = w * - 1 ; } let x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 ; if ( ! xSignIsPositive ) { x = - x ; } return ( x % 11 + 11 ) % 11 ; } let A = " " ; let B = " " ; let C = " " ; document . write ( findMissingDigit ( A , B , C ) ) ;