我想看看一个数字是否等于另一个数字的平方根。我写了一个方法来实现这一点,但它会搜索到最大值Int32
(这需要很长时间)。我真的很想搜索大于 100 的数字(我目前的限制),但我不确定最大值应该是多少。
public static string IsSqrtOfNum(double num, int counter = 1)
{
while (true)
{
if (Math.Sqrt(counter) == num)
{
return "√" + counter.ToString();
}
if (counter >= 100) break;
counter++;
}
return num.ToString();
}