编写一个程序1!+2!+3!+...+100!用BASIC语言

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 22:32:20
编写一个程序1!+2!+3!+...+100!用BASIC语言

编写一个程序1!+2!+3!+...+100!用BASIC语言
编写一个程序1!+2!+3!+...+100!用BASIC语言

编写一个程序1!+2!+3!+...+100!用BASIC语言
public class SetPerformance {
static int f(int n){//计算阶乘函数
int fn = 0;
if(n==1) return 1;
fn=n*f(n-1);
return fn;
}
public static void main(String[] args) throws Exception{
System.out.println("输入一个数字然后计算其所有阶乘的和");
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int fn;
double sum=0;
fn=Integer.parseInt(b.readLine());
sum+=f(fn);
System.out.println(sum);
}
}
这是我用java编写的,估计算法都差不多,你自己看看吧