Nov 8, 2013 at 4:37pm UTC
function divide(x;y)
Input: Two n-bit integers x and y, where y&>=1
Output: The quotient and remainder of x divided by y
if x=0: return (q,r)=(0,0)
(q,r)=divide(floor( x/2),y)
q=2*q r=2*r
if x is odd: r=r+1
if r&y: r=r y; q=q+1
return (q,r)
thanks
Nov 8, 2013 at 4:54pm UTC
We don't write code for you here. Have a go at it. If you run into specific problems, then show us the code you've written and we'll try and help.
Nov 9, 2013 at 4:11am UTC
this is my code for division algorithm
but not correct
you can help me to edit it ??
--------------------------------------------
#include <iostream>
#include <math.h>
using namespace std;
int division(int x,int y);
int main()
{
int a,b,c,d;
cout<<"enter your numbers"<<endl;
cin>>a>>b;
cout<<"your div is "<<division(a,b);
return 0;
}
int division(int x,int y )
{
int q,r;
if(x==0)
{
return (q,r)=(0,0);
}
(q,r)=division(floor(x/2),y);
q=2*q;
r=2*r;
if(x%2!=0)
{
r=r+1;
}
if(r>=y)
{
r=r-y;
q=q+1;
}
return (q,r);
}
}