new.learner67
BAN USER{
private static int recMultiplyHelper(int x, int y)
{
if (y == 1)
return x;
else
return x + recMultiply(x, y - 1);
}
public static int Multiply(int x, int y)
{
if (x == 0 || y == 0)
return 0;
bool isAnswerNegative = false;
if (x < 0 && y > 0 || x > 0 && y < 0)
isAnswerNegative = true;
if (x < 0)
{
x = x - x - x;
}
if (y < 0)
{
y = y - y - y;
}
int answer = recMultiplyHelper(x, y);
if (isAnswerNegative)
{
answer = answer - answer - answer;
}
return answer;
}
}
Could u please give sample code for this algorithm
- new.learner67 October 18, 2009incorrect and confusing solution by Anonymous
- new.learner67 October 17, 2009
-(x) is sort of multiplication operation -1*x and violates a constriant
- new.learner67 October 26, 2009