我想要做的是使用for
循环,计算根下的根之和(不是数学家,不知道你怎么称呼它)。
顺序应该是这样的:
Sqrt(2 + Sqrt(2 + ... + Sqrt(2))), where n > 0.
例如,如果n = 3
在for
循环上(while i = 1, i++)
,它应该使这个算术序列:
sum += Math.Sqrt(2 + Math.Sqrt(2 + Math.Sqrt(2)));
如果 n = 4:
sum += Math.Sqrt(2 + Math.Sqrt(2 + Math.Sqrt(2 + Math.Sqrt(2))));
所以问题是我不知道如何n
通过在根下添加根直到循环结束来循环槽。
我的代码模板
public static double GetSumOfRoots(int n)
{
double sum = 0;
for (int i = 1; i <= n; i++)
{
sum += ...;
}
return sum;
}
如果我的描述不清楚,请告诉我,我会尽力而为,谢谢。