问题:

特殊数列:后一项是前一项的平方根,先有第n的值,求n项到某项的和

 

分析:根据数列规则求解

 

code:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         Scanner s = new Scanner(System.in);
 7         double n;
 8         int m;
 9         
10         while(s.hasNext()) {
11             n = s.nextDouble();
12             m = s.nextInt();
13             double temp = n;
14             
15             //迭代求和
16             for(int i=1;i<m;i++) {
17                 temp = Math.sqrt(temp);
18                 n+=temp;
19             }
20             System.out.printf("%.2f\n",n);
21             
22         }
23         s.close();
24     }
25     
26 }

 

相关文章:

  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
猜你喜欢
  • 2021-12-10
  • 2023-03-02
  • 2021-04-24
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
相关资源
相似解决方案