How to find the remainder without using modulo operator in Node.js

2 Answers

0 votes
const n = 29;
const divisor = 6;
       
let remainder = n;
   
while (remainder >= divisor) {
       remainder = remainder - divisor;
}
   
console.log("The remainder is: " + remainder);
 
   
   
   
   
/*
run:
   
The remainder is: 5
   
*/

 



answered May 18, 2022 by avibootz
0 votes
const n = 29;
const divisor = 6;
       
const remainder = n - divisor * parseInt(n / divisor);
   
console.log("The remainder is: " + remainder);
 
   
   
   
   
/*
run:
   
The remainder is: 5
   
*/

 



answered May 18, 2022 by avibootz

Related questions

2 answers 223 views
2 answers 200 views
2 answers 250 views
2 answers 209 views
2 answers 180 views
...