Implement a function that calculates the remainder of a given dividend and divis
ID: 3881967 • Letter: I
Question
Implement a function that calculates the remainder of a given dividend and divisor without using the modulus (%) operator. You can assume the dividend and divisor are both positive, non-zero values.calculateRemainder(15, 2); // returns 1
Implement a function that calculates the remainder of a given dividend and divisor without using the modulus (%) operator. You can assume the dividend and divisor are both positive, non-zero values.
calculateRemainder(15, 2); // returns 1
Implement a function that calculates the remainder of a given dividend and divisor without using the modulus (%) operator. You can assume the dividend and divisor are both positive, non-zero values.
calculateRemainder(15, 2); // returns 1
Explanation / Answer
CalculateRemainder(int dividend, int divisor)
{
return (dividend - divisor * (dividend / divisor));
}
Example dividend 15
Divisor 2
15-2*(15/2)
=15-2*7
=15-14
=1
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.