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 201 views
2 answers 176 views
2 answers 227 views
2 answers 176 views
2 answers 161 views
...