我如何在C#计算圆周率? [英] How do I calculate PI in C#?

查看:886
本文介绍了我如何在C#计算圆周率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用C#计算圆周率的值?

How can I calculate the value of PI using C#?

我想这将是通过一个递归函数,如果是的话,那会是什么样子,以及是否有任何数学公式​​对其进行备份?

I was thinking it would be through a recursive function, if so, what would it look like and are there any math equations to back it up?

我不是太挑剔的表现,主要是如何去了解它从学习的角度来看。

I'm not too fussy about performance, mainly how to go about it from a learning point of view.

推荐答案

如果你想递归:

PI = 2 * (1 + 1/3 * (1 + 2/5 * (1 + 3/7 * (...))))

这将成为,经过一番重写:

This would become, after some rewriting:

PI = 2 * F(1);

使用F(ⅰ):

double F (int i) {
    return 1 + i / (2.0 * i + 1) * F(i + 1);
}

艾萨克·牛顿(你可能已经听说过他;))想出了这一招。
请注意,我离开了终止条件,以保持它的简单。在现实生活中,你有种需要一个。

Isaac Newton (you may have heard of him before ;) ) came up with this trick. Note that I left out the end condition, to keep it simple. In real life, you kind of need one.

这篇关于我如何在C#计算圆周率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆