+ 1

How to find remainder of two values without using % in c++

22nd Oct 2017, 3:18 PM
Shukrullah Jan
Shukrullah Jan - avatar
3 ответов
+ 5
Use simple math with integer division. quotient = numerator / denominator remainder = numerator - quotient*denominator #include <iostream> using namespace std; int main() { int numerator = 10; int denominator = 3; int remainder = numerator - (numerator/denominator)*denominator; cout << remainder; return 0; }
22nd Oct 2017, 3:33 PM
ChaoticDawg
ChaoticDawg - avatar
+ 13
while (dividend > divisor) dividend -= divisor; std::cout << "Remainder : " << dividend;
22nd Oct 2017, 3:31 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
substract one value from another until you get a negative number
22nd Oct 2017, 3:23 PM
Eligijus Silkartas
Eligijus Silkartas - avatar