编写查找椭圆周长的程序

2024 年 9 月 5 日 | 阅读 3 分钟

在用不同的编程语言编写计算椭圆周长的程序之前,我们首先需要了解什么是椭圆及其周长的公式。

什么是椭圆?

椭圆被描述为一个平面上的曲线,它围绕两个焦点,使得到两个焦点的距离之和对于曲线上每一点都保持不变。

椭圆的周长

Perimeter of Ellipse = 2 * π * sqrt( (a2 + b2) / 2 )
Where, a is the semi-major axis of an ellipse, b is the semi-minor axis of the same ellipse, and the value of π is 3.14. 

用不同的编程语言计算椭圆周长的程序

程序 1:用 C 语言编写程序

以上 C 程序的输出

Enter the semi-major axis of the ellipse:5
Enter the semi-minor axis of the ellipse:10
Perimeter of the ellipse is: 49.647758

程序 2:用 Java 语言编写程序

以上 Java 程序的输出

The Perimeter of a ellipse is:
49.647759264643554

程序 3:用 PHP 编程语言编写程序。

以上 PHP 程序的输出

49.647759264644

程序 4:用 Python 编程语言编写程序。

以上 Python 程序的输出

49.647759264644