您的位置:首页 > 移动开发 > 微信开发

小程序(求N个数的阶乘)

2010-04-07 20:51 134 查看
using System;public class Factorial{

public long factorial(long x){

return ((x<=1) ? 1 : x*(factorial(x-1)));

}

}

public class FactorialSum

{

public static void Main()

{

long temp=0;

long sum=0;

Console.WriteLine ("输入一个数:");

int x=int.Parse (Console.ReadLine ());

for(int i=1;i<=x;i++)

{

Factorial f1=new Factorial ();

temp+=f1.factorial (i);

}

sum+=temp;

Console.WriteLine ("1!+2!+3!+...+a!="+sum);

}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐