Program for quotient and remainder of big number | Function to calculate the modulus ; Store the modulus of big number ; Do step by step division ; Update modulo by concatenating current digit . ; Update quotient ; Update mod for next iteration . ; Flag used to remove starting zeros ; Driver Code
function modBigNumber ( num , m ) { let vec = [ ] ; let x = 0 ; let mod = 0 ; for ( let i = 0 ; i < num . length ; i ++ ) { digit = num [ i ] - ' ' ; mod = mod * 10 + digit ; quo = parseInt ( mod / m ) ; vec [ x ++ ] = quo ; mod = mod % m ; } document . write ( " " + mod + " " ) ; document . write ( " " ) ; let zeroflag = 0 ; for ( let i = 0 ; i < x ; i ++ ) { if ( vec [ i ] == 0 && zeroflag == 0 ) continue ; zeroflag = 1 ; document . write ( vec [ i ] ) ; } return ; } let num = " " ; let m = 487 ; modBigNumber ( num , m ) ;