描述
输入
输入两个数x和m。
输出
输出前m项的和,保留5位小数。
样例输入
0.3 2
样例输出
0.29550
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
double x,m,sum=0,y,z,v,i,j;
scanf("%lf%lf",&x,&m);
for(i=1;i<=m;i++)
{
z=pow(x,2*i-1);
v=pow(-1,i-1);
for(y=1,j=1;j<=2*i-1;j++)//分母阶乘,y初始值为1
{
y=y*j;
}
sum+=v*z/y;
}
printf("%.5f",sum);
return 0;
}
pow(x,y)用来求x的y次幂,且x,y及函数值为double型,需加上#include <math.h>头文件