class Program
{
public int Factorial(int num)
{
int result;
if (num == 1)
{
return 1;
}
else
{
result = Factorial(num - 1) * num;
}
return result;
}
class Test
{
static void Main(string[] args)
{
Console.WriteLine("请说出一个整数,我将森弊算出他的阶乘此铅族");
int a = Convert.ToInt32(Console.ReadLine());
Program n = new Program();
Console.WriteLine("激手{0}的阶乘是{1}",a,n.Factorial(a));
Console.ReadKey();
}
}
}
public int jc(int n) {
if(n==1)
return 1;
else
return n*jc(n-1);
}
private double jc(int n)
{
double jc1 = 1;
for (int i = 1; i <= n;i++ )
{
jc1 = jc1 * i;
}
return jc1;
}
public static int jiecheng(int n)
{
if (n == 1)
return 1;
else
return n * jiecheng(n - 1);
}
你好
public int GetResult(int n)
{
switch(n)
{
case 0:
case 1:
return 1;
default :
return n*GetResult(n-1);
}
}