Computer Science, asked by Doctordrayo, 11 months ago

Hima loves to do everything differently. She wants to add two numbers using functions. She want to add two numbers using bit-wise operators. Can you help her?


#include
int Add(int, int);
int main()
{
int r,a;
std::cin>>r>>a;
std::cout<< Add(r,a);
return 0;
}
int Add(int x, int y)
{
int carry;
while (y != 0)
{
// Your code goes here
}
return x;
}

Answers

Answered by Yamini1999
9

Answer:

#include<iostream>

int Add(int, int);

int main()  

{  

   int r,a;

   std::cin>>r>>a;

   std::cout<< Add(r,a);  

   return 0;  

}  

int Add(int x, int y)  

{  

   int carry;

   while (y != 0)  

   {  

      int carry = x & y;

      x= x ^ y;

      y = carry << 1;

   }  

   return x;  

}  

Explanation:

Similar questions