编写一个程序,求s=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)的值Cyuyan
时间: 2023-12-16 07:04:43 浏览: 74
以下是Java语言实现求s=1+(1+2)+(1+2+3)+...+(1+2+3+...+n)的程序:
```java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
int i, s = 0, t = 0;
for (i = 1; i <= n; i++) {
t = t + i;
s = s + t;
}
System.out.println(s);
}
}
```
阅读全文