谁能建议我一种不使用乘法(*)符号来乘以十进制数的方法。我知道它看起来像家庭作业,但我只想知道如何实现这一点。我已经为正整数和负整数做了这个,如下所示:
int first = 2;
int second =2;
int result = 0;
bool isNegative = false;
if (first < 0)
{
first = Math.Abs(first);
isNegative = true;
}
if (second < 0)
{
second = Math.Abs(second);
isNegative = true;
}
for (int i = 1; i <= second; i++)
{
result += first;
}
if (isNegative)
result = -Math.Abs(result);
想将其乘以小数:
decimal third = 1.1;
decimal fourth = 1.2;
谢谢