解题思路:
找规律 求An 再求Sn
注意事项:
参考代码:
import java.util.Scanner; public class Main { /* Sine之舞 * An=sin(1–sin(2+sin(3–sin(4+...sin(n))...) * Sn=(...(A1+n)A2+n-1)A3+...+2)An+1 * A1 = sin(1) * A2 = sin(1-sin(2)) * A3 = sin(1-sin(2-sin(3))) * A4 = sin(1-sin(2+sin(3-sin(4)))) * * S1 = sin(1)+1 * S2 = (sin(1)+2)sin(1-sin(2))+1 * S3 = ((sin(1)+3)sin(1-sin(2))+2)sin(1-sin(2+sin(3)))+1 * S4 = (((sin(1)+4)sin(1-sin(2))+3)sin(1-sin(2+sin(3)))+2)sin(1-sin(2+sin(3-sin(4))))+1 */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.close(); Sn(n); } public static String An(int n) { // 求An(i) String str = new String(); for (int i = 1; i <= n; i ++) { if (i != n && i % 2 == 0) { // 如果不是最后一个且为偶数,则+ String s = "sin(" + i + "+"; str = str + s; } else if (i != n && i % 2 == 1){ // 如果不是最后一个且为偶数,则- String s = "sin(" + i + "-"; str = str + s; }else { String s = "sin(" + i; // 最后一个直接衔接上 str = str + s; } } for (int i = 1; i <= n; i ++) { // 末尾加上n个右括号 str = str + ")"; } return str; } public static void Sn(int n) { // 求Sn String Sn = new String(); int k = n; for (int i = 1; i <= n; i++) { // 进行n次循环,将A1到An进行累乘 String s = An(i) + "+" + k; if (i == 1) { Sn = s; } else{ Sn = "(" + Sn + ")" + s; } k--; } System.out.println(Sn); } }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:737 |
WU-输出正反三角形 (C++代码)浏览:1100 |
用筛法求之N内的素数。 (C语言代码)浏览:890 |
【偶数求和】 (C语言代码)浏览:460 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:585 |
A+B for Input-Output Practice (II) (C语言代码)浏览:622 |
快速排序算法1浏览:996 |
1199题解浏览:707 |
P1002 (C语言代码)浏览:1028 |
这是我的第一篇文章浏览:265 |