求C#编程1!+2!+3!+4!+5!
谢谢啦
2010-03-12 09:18
程序代码:int count = 0;
for (int i = 1; i <= 5; i++)
{
count += i;
}
2010-03-12 10:21
程序代码: static void Main(string[] args)
{
Console.WriteLine(GetValues(5));
Console.ReadLine();
}
public static int GetValues(int n)
{
int Num = 0;
for (int i = 0; i < n; i++)
{
Num += Foo(n);
}
return Num;
}
public static int Foo(int n)
{
if (n > 0)
{
return Foo(n - 1) * n;
}
else
{
return 0;
}
}

2010-03-12 11:46
2010-03-12 11:48
程序代码: static void Main(string[] args)
{
Console.WriteLine(GetValues(5));
Console.ReadLine();
}
public static int GetValues(int n)
{
int Num = 0;
for (int i = 0; i < n; i++)
{
Num += Foo(n);
}
return Num;
}
public static int Foo(int n)
{
if (n > 0)
{
return Foo(n - 1) * n;
}
else
{
return 1;
}
}刚才发快了,没注意判断了,Foo函数,当N<0时,返回1,按理说负数是没有阶乘的!

2010-03-12 12:14
2010-03-12 12:35
2010-03-12 18:51
2010-03-12 18:51
2010-03-12 23:30
2010-03-21 11:17