开门见山
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Program
{
static void Main(string[] args)
{
int n;
int.TryParse(Console.ReadLine(), out n);
Console.WriteLine(Factorial(n));
Console.ReadKey();
}
static int Factorial(int n)
{
if (n == 0)
{
return 1;
}
return n * Factorial(n - 1);
}
}
}
运行:
注意
最高支持到31阶乘:
34阶乘直接溢出为0