answersLogoWhite

0


Best Answer

int dividend,divisor,remainder;

int division(int p,int q){

int quotient=1;

/*if divisor and diviend are equal then quotient=1*/

if(p==q){

remainder=0;

return 1;

}

/*if dividend is smaller than divisor then remainder=dividend*/

if(p<q){

remainder=p;

return 0;

}

/*shift left till divisor > dividend*/

while(p>=q){

q<<=1;

quotient<<=1;

}

/*shift right for one time so that divisor become smaller than dividend*/

q>>=1;

quotient>>=1;

/*again call division recurcively*/

quotient+=division(p-q,divisor);

return quotient;

}

int main(){

cout<<"\nEnter dividend:";

cin>>dividend;

cout<<"\nEnter divisor:";

cin>>divisor;

cout<<"\nQuotient:"<<division(dividend,divisor);

cout<<"\nRemainder:"<<remainder;

//system("pause");

return 0;

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Anonymous

Lvl 1
4y ago

Recursively

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you divide two numbers without division operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp