Notes: This Problem is about Half Adder Circuit. We know From Boolean Algebra, To Add two digit we need to xor them. But If there is carry operation Then we should also xor carry input. That is Full Adder Circuit. But In Half Adder Circuit , Addition method does not consider carry input. So Sum is= A Xor B.
That's why 4+6=2 as in binary 100^110=010.
input and output format should be in %d format. cin, cout creates problem with xor operator for some test cases
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x,y,z;
//freopen("10469.txt","r",stdin);
//freopen("10469out.txt","w",stdout);
while(scanf("%d %d",&x,&y)!=EOF)
{
z=x^y;
printf("%d\n",z);
}
return 0;
}
0 comments:
Post a Comment