C#使用递归来计算阶乘

using System;

namespace MyApplication {

   class Factorial {

      public int display(int n) {
         if (n == 1)
            return 1;
         else
            return n * display(n - 1);
      }

      static void Main(string[] args) {
         int value = 5;
         int ret;

         Factorial fact = new Factorial();
         ret = fact.display(value);
         Console.WriteLine("Value is : {0}", ret );
         Console.ReadLine();
      }
   }
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/265890.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论