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
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
Accountancy,
5 months ago
English,
5 months ago
Math,
5 months ago
Chemistry,
11 months ago
Psychology,
11 months ago