热门关键字: jsp web pl/sql pl webwor   →开发工具  操作系统
当前位置 : 无忧IT编程网 > 其它语言 > C++ > 正文

使用C++实现椭圆周长的计算

来源:转载作者:无忧时间:08-01-24

    我们数学上经常遇到的一个问题,椭圆周长的计算,今天我们用程序来实现一下看看吧。

// use 2nd one

// calculate circumference of an ellipse

 

#include "iostream"

using namespace std;

#define _USE_MATH_DEFINES

#include "cmath"

 

const int LIMIT = 10; // items number

 

double circumference(double semimajor, double semiminor);

 

int main()

{

     double res;

     res = circumference(1, 2);

     cout << "The circumference is: " << res << endl;

} 

 

 

 

double circumference(double semimajor, double semiminor)

{

     double item[LIMIT];

     double e;

     if(semimajor >= semiminor)

     {

         e = sqrt(1 - pow(semiminor / semimajor, 2));

     }

     else

     {

         e = sqrt(1 - pow(semimajor / semiminor, 2));

     }

 

     double l_deno, l_numa, pe, r_deno, mo, ne;

     int i;

     for(int j = 1; j < LIMIT; ++j)

     {

         for(i = 1, l_deno = l_numa = mo = 1, ne = 2; i < j + 1;

              ++i, mo += 2, ne += 2)

         {

              l_numa *= mo;

              l_deno *= ne;         

         }

 

         pe = pow(e, 2 * j);

         r_deno = 2 * j - 1;

 

         item[j - 1] = l_numa * l_numa * pe /(l_deno * l_deno * r_deno);

     }

 

     double tmp = 0.0;

     for(int k = 0; k < LIMIT - 1; ++k)

     {

         tmp += item[k];

     }

 

     double l = 2 * M_PI * semimajor * (1 - tmp);

      

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 验证码: 验证码
查看所有评论
相关文章
站长推荐