Division without / or *

Q: Write a function to perform integer division without using either the / or * operators. Find a fast way to do it.

A:

void int_div(int dividend, int divisor)
{
if(divisor>dividend)
return;

remainder = 0;
quotient = 0;

while(remainder > divisor)
{
remainder = dividend - divisor;
quotient += 1;
}
return;
}

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.