#include"stdio.h"
#include"math.h"
fun(double x,double n)
{
double a,b,c,d,e,g,h,i,j;
double sum=1,0,f;
d=1,a=2,e=2,b=1;
for(;d<=n;d++,a=a*2,e*=2)
{
i=pow(x,a);
j=pow(-1.0,d);
b=i*j;
g=1.0;
for(h=1.0;h<=e;h++)
{
g=g*h;
}
f=b/g;
sum=sum+f;
}
return sum;
}
main()
{
double x,n,sum;
scanf("%f,%f",&x,&n);
sum=fun(x,n);
printf("%f",sum);
}
3 回答
望远
TA贡献1017条经验 获得超1032个赞
#include"stdio.h" #include"math.h" double fun(double x,double n)//注意返回值类型 { double a,b,c,d,e,g,h,i,j; double sum=1.0,f; d=1,a=2,e=2,b=1; for(;d<=n;d++,a=a*2,e*=2) { i=pow(x,a); j=pow(-1.0,d); b=i*j; g=1.0; for(h=1.0;h<=e;h++) { g=g*h; } f=b/g; sum=sum+f; } return sum; } main() { double x,n,sum; scanf("%lf,%lf",&x,&n); //注意double数据类型的输入输出格式 sum=fun(x,n); printf("%lf",sum); }
Anjaxs
TA贡献2条经验 获得超0个赞
#include"stdio.h" #include"math.h" /** * (1*x^0)/1! + -1*x^2/2! + ... + [-1^(n-1)]*[x^2*(n-1)]/n! **/ double fun(double x,double n) { double a, b, c, d, e, g, h, i, j; double sum = 1.0, f; d = 1, a = 2, e = 2, b = 1; for(; d <= n; d++, a = a*2, e *= 2) { i = pow(x, a); j = pow(-1.0, d); b = i*j; g = 1.0; for(h=1.0; h <= e; h++) { g = g*h; } f = b/g; sum = sum + f; } return sum; } main() { double x,n,sum; scanf("%f,%f",&x,&n); sum=fun(x,n); printf("%f",sum); }
可能是这样
- 3 回答
- 0 关注
- 1309 浏览
添加回答
举报
0/150
提交
取消