
请用迭代代函数调用来计算下试:f(x)=x-x^3/3!+x^5/5!-x^7/7!+...
展开全部
#include<stdio.h>
double x;
double myfuc1(unsigned int m)
{
static unsigned int n = 0;
static double x1 = 1;
if(m<n){n=0; x1=1.0;}
for(; n<=m; n++) x1 *= x /(n+1);
return x1;
}
double myfuc2(double fx,unsigned int m)
{
unsigned int i;
double res;
x = fx;
for(res=0.0,i=0; i<=m; i++)
res += myfuc1(i*2+1);
return res;
}
void main()
{
double fx;
printf("输入一小于20的正实数x:");
scanf("%lf",&fx);
printf("\n输入的数:%lf",fx);
printf("\n计算结果:");
for(int ii=1;ii<=20;ii++)
printf("\n前%d项和: %lf:", ii, myfuc2(fx,ii));
//已实验过,如果输入的值过大,要很多项之后结果才稳定成一个常数
}
double x;
double myfuc1(unsigned int m)
{
static unsigned int n = 0;
static double x1 = 1;
if(m<n){n=0; x1=1.0;}
for(; n<=m; n++) x1 *= x /(n+1);
return x1;
}
double myfuc2(double fx,unsigned int m)
{
unsigned int i;
double res;
x = fx;
for(res=0.0,i=0; i<=m; i++)
res += myfuc1(i*2+1);
return res;
}
void main()
{
double fx;
printf("输入一小于20的正实数x:");
scanf("%lf",&fx);
printf("\n输入的数:%lf",fx);
printf("\n计算结果:");
for(int ii=1;ii<=20;ii++)
printf("\n前%d项和: %lf:", ii, myfuc2(fx,ii));
//已实验过,如果输入的值过大,要很多项之后结果才稳定成一个常数
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |