题目描述
输入x,计算上面公式的前10项和。
输入
输入一个实数x。
输出
输出一个实数,即数列的前10项和,结果保留3位小数。
样例输入 Copy
1
样例输出 Copy
0.841
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
double x=input.nextDouble();
double w=0;
double deno = 1.0; //第一项的分母
double numerator = x; //第一项的分子
double flag = 1.0; //第一项的符号
for(int i=1;i<=10;i++) {
w+=(numerator/deno)*flag;
flag=-flag;
numerator=numerator*x*x;
deno = deno *(2 * i) * ( 2 * i + 1);
}
System.out.printf("%.3f",w);
}
}