#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 回答

望遠(yuǎn)
TA貢獻1017條經(jīng)驗 獲得超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數(shù)據(jù)類型的輸入輸出格式 ?sum=fun(x,n);? ?printf("%lf",sum); ?}

Anjaxs
TA貢獻2條經(jīng)驗 獲得超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 關(guān)注
- 1364 瀏覽
添加回答
舉報
0/150
提交
取消