Add two numbers without using +,-,*,/

by manojgumber

Method 1
int add(int a, int b)
{
while(a–)
b++;
return b;
}

Method 2
int add(int a, int b)
{
char *p=a;
return &p[b];
}

Method 3
By using the concept of binary adders, If p and q are two bits , then p^q is their sum and p&q is the carry generated by them
int
add (int a, int b)
{
int sum, carry;
do
{
sum = a ^ b;
carry = a & b;
a = sum;
b = carry << 1;
}
while (carry);

return sum;
}

Advertisements