-------------------------------------------------------------------------------------------------------------------有一分数序列: 2/1 3/2 5/3 8/5 13/8 21/13… 求出这个数列的前N项之和,保留两位小数。
输入
N
输出
数列前N项和
样例
输入
10
输出
16.48
import java.util.Scanner;
public class Main {
public static double[] ifNumber(int n) {
double[]a=new double[n+1];
double front=1;
double rite=2;
a[0]=1;
a[1]=2;
int t=2;
while(t<n+1)
{
double num=front+rite;
front=rite;
rite=num;
a[t]=num;
t++;
}
return a;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
double []a=ifNumber(t);
sc.close();
double num=0;
for(int i=0;i<t;i++)
{
num=num+a[i+1]/a[i];
}
System.out.printf("%.2f",num);
}
}