Question
Can you please change this code to c++ as it is written in c language. #include #include void division(char x, char y) { register char
Can you please change this code to c++ as it is written in c language.
#include
void division(char x, char y) { register char A, M, Q;
unsigned char t, s, r;
int i;
Q = x; M = y; A = 0;
//display initial values in A, Q and M printf("Initially: A = %d Q = %d M = %d ", A, Q, M);
Q = abs(x); M = abs(y);
r = sizeof(char)*8;
t = 1 << (r-1);
for(i=0; i < r; i++) { //shift left AQ A = A <<1; s = Q & t; s = s >> (r-1); Q = Q << 1; A = A | s;
//A = A -M A = A - M;
//MSB of A s = A & t; s = s >> (r-1);
//check MSB if(s==0) //Q[0] = 1 Q = Q | 1; else { //Q[0] = 0 Q = Q | 0; //restore A A = A + M; } } if(x<0) A = ~A + 1;
if(x<0 && y>0 || x>0 && y<0) Q = ~Q + 1;
//display Quotient and Remainder printf("Quotient = %d\t", Q); printf("Remainder = %d ", A);
printf("%dR%d ", Q, A);
}
int main() { int a, b;
printf("Enter dividend and divisor: "); scanf("%d%d", &a, &b);
division(a, b); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started