Thursday, July 9, 2009

How can we add two numbers without using a + operator in 'C' language?

this means Is there any built in functions in C for this operation?

How can we add two numbers without using a + operator in 'C' language?
private int Sum(int a, int b) {


int x = a ^ b;


while ((a %26amp; b) != 0) {


b = (a %26amp; b) %26lt;%26lt; 1;


a = x;


x = a ^ b;


}


return x;


}





private uint Product(uint a, uint b) {


uint p = 0;


while (b != 0) {


if ((b %26amp; 1) == 1) p = Sum(p, a);


a %26lt;%26lt;= 1;


b %26gt;%26gt;= 1;


}


return p;


}
Reply:its quite sinple why dont u use a-(-b)
Reply:Search for some function in ' math.h ' include file


No comments:

Post a Comment