C
codergem
How to add two numbers without using the plus operator?
How to add two numbers without using the plus operator?
aahhh!!!!
not this way.
using bitwise operators ..
You are asking us for help. It pays to be polite if you are askingWhat are you trying to prove by this??
If u know its answer then post here...or else go to hell.
"[email protected] said:How to add two numbers without using the plus operator?
How to add two numbers without using the plus operator?
How to add two numbers without using the plus operator?
Daniel said:Why would you want to?
What are you trying to prove by this??
If u know its answer then post here...or else go to hell.
red floyd wrote:
Markus said:a-(-b)
How to add two numbers without using the plus operator?
Old said:Doesn't work if they are ints and b is INT_MIN and INT_MIN < -INT_MAX.
Markus said:Yes, I guess the standard labels this as undefined behaviour. In
reality it will work even for this corner case just fine with every
existing implementation.
include<stdio.h>
int add(int x, int y) {
int a, b;
do {
a = x & y;
b = x ^ y;
x = a << 1;
y = b;
} while (a);
return b;
}
int main( void ){
printf( "2 + 3 = %d", add(2,3));
return 0;
}
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.