answersLogoWhite

0

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

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
JudyJudy
Simplicity is my specialty.
Chat with Judy
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers

Recursively

User Avatar

Anonymous

4y ago
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