Was asked how I would implement division without using division or mod operators. The answer should return in the form quotient r remainder.
Sigiloso
Besides the returning format, and according the algorithm above, I would write in C the following function: void div(int N, int D) { int Q = 0; int x = N; int it = 1; while (x >= D) { if ( x < (D << it) ) { x -= (D << (it-1)); Q += (1 << (it-1)); it = 0; } it++; } cout << "Quotient: " << Q << " Remainder: " << x << endl; }