Popular Posts

Thursday, December 30, 2010

Multiply two numbers without using loops or multiplication or division

We can implement this by using recursive operation.
public static int multiply(int x, int y) {
if (y == 0)
return 0;

// if y is positive,Add x one by one
if (y > 0)
return (x + multiply(x, y - 1));
else
return -multiply(x, -y);
}

No comments:

Post a Comment