#include "stdio.h"
float getSeriesSum(int num)
{
int molecule=2;
int denominator=1;
float result=0.0;
int i;
for(i=0;i<num;i++)
{
result+=(float)molecule/denominator;
molecule=molecule+denominator;
denominator=molecule-denominator;
}
return result;
}
float getSeriesSum_0(int num)
{
int molecule=2;
int denominator=1;
int res_molecule=0,res_denominator=1;
int i;
for(i=0;i<num;i++)
{
res_molecule=res_molecule*denominator+molecule*res_denominator;
res_denominator=res_denominator*denominator;
molecule=molecule+denominator;
denominator=molecule-denominator;
}
return (float)res_molecule/res_denominator;
}
int main()
{
int i;
double m=1,n=2,a=0;
for(i=1;i<=20;)
{a+=n/m;
/*让商值不断累积最后赋予a[20]*/
n=m+n;
m=n-m;
/*把数列规律重新定义m,n值*/
i++;
}
printf("%f\n",a);
//cout<<a[20]<<endl
system("pause");
return 0;
}