![]() |
#2
phillip1602012-05-11 15:42
|
只有本站会员才能查看附件,请 登录

#include"iostream.h"
#include"math.h"
int jiecheng(int x)
{
int j,k;
for(j=1,k=1;j<=x;j++)
k=k*j;
return k;
}
double fun(double x,double eps=1e-6)
{
double s;
int i;
for(i=1,s=x;pow(x,2*i+1)/jiecheng(2*i+1)>eps;i++)
{
s=s+pow(-1,i)*pow(x,2*i+1)/jiecheng(2*i+1);
}
s=s+pow(-1,i)*pow(x,2*i+1)/jiecheng(2*i+1);
return s;
}
void main()
{
double x;
cout<<"Input x please x=";
cin>>x;
cout<<'\n'<<fun(x)<<'\n';
}
#include"math.h"
int jiecheng(int x)
{
int j,k;
for(j=1,k=1;j<=x;j++)
k=k*j;
return k;
}
double fun(double x,double eps=1e-6)
{
double s;
int i;
for(i=1,s=x;pow(x,2*i+1)/jiecheng(2*i+1)>eps;i++)
{
s=s+pow(-1,i)*pow(x,2*i+1)/jiecheng(2*i+1);
}
s=s+pow(-1,i)*pow(x,2*i+1)/jiecheng(2*i+1);
return s;
}
void main()
{
double x;
cout<<"Input x please x=";
cin>>x;
cout<<'\n'<<fun(x)<<'\n';
}