题目:
求n阶乘的和:
例如输入:3
输出 :10
即1!+2!+3!=10
import java.util.Scanner;
public class 求阶乘 {
public static void main(String[] args) {
int sum=0;
int num=0;
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
for (int i = 0; i <=n; i++) {
num+=i;
sum+=num;
}
System.out.println(n+"的阶乘和为:"+sum);
}
}