A division of one positive integer number by another positive integer number is often performed in elementary schools as repeated subtraction. input two positive integer number ,x and y.Then compute and display the quotient q and the remainder r of x divided y without using any division operator or function(slash operator/modulo operator).
1
Expert's answer
2011-10-14T11:12:24-0400
/*I used a recursive function to calculate the quotient and the remainder.*/
#include<stdio.h> #include<iostream> using namespace std; int x, y, r;
int division(int tempdividend, int tempdivisor) { int q = 1; if (tempdivisor == tempdividend) { r = 0; return 1; } else if (tempdividend < tempdivisor) { r = tempdividend; return 0; }
Comments
Leave a comment