Search This Blog

Friday, 21 August 2020

addition without using + operator (using bit wise operator)

 #include<iostream>

using namespace std;

int add(int,int);



int main()

{

int x,y;

cout<<"Enter the 2 numbers:"<<endl;

cin>>x>>y;

cout<<"addition is "<<add(x,y);

return 0;

}

int add(int a,int b)

{

int sum=a^b;

int carry=a&b;

while(carry!=0)

{

carry<<=1;

a=sum;

b=carry;

sum=a*b;

carry=a&b;

}

return sum;

}


No comments:

Post a Comment

Search This Blog

Contact Form

Name

Email *

Message *

Popular Posts