+ 1
How to find remainder of two values without using % in c++
3 Respuestas
+ 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;
}
+ 13
while (dividend > divisor)
dividend -= divisor;
std::cout << "Remainder : " << dividend;
+ 2
substract one value from another until you get a negative number