loner_li 机试题 阶乘

  class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <=10; i++)
            {
                Console.WriteLine("{0}的阶乘是{1}",i,Factorial(i));
            }
            Console.ReadKey();
        }

        public static long Factorial(long n)
        {
            if (n == 1)
            {
                return 1;
            }
            else
            { return n * Factorial(n-1); }
        }
    }

你可能感兴趣的:(loner_li 机试题 阶乘)