UVA 10469 To Carry or not to Carry





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;

}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment