且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

递归code。在一系列的4/1 - 4/3 + 4/5

更新时间:2023-02-10 15:02:39

我不认为递归是必要的。这是很容易解决了迭代。 我看到了下面的模式。分母是1,3,5,7-奇数。这是我%2。 分数的符号被交替+和 - 之间 - 。使用迭代的模数2 -1或不乘以电流份额。那么+ =运算总和。

I don't think recursion is necessary. This is easily solved with iteration. I see the following pattern. The denominator is 1,3,5,7- odd numbers. That's i%2. The sign of the fraction is alternating between + and -. Use the modulus 2 of the iteration to multiply the current fraction by -1 or not. Then += to the running sum.