ITPub博客

首页 > 应用开发 > .net > c# 阶乘递归算法

c# 阶乘递归算法

原创 .net 作者:wzr1123 时间:2019-01-06 00:24:57 0 删除 编辑
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace jiecheng{
    class jiecheng    {
        public int Jc(int num)
        {
            
            return num > 0 ? num *Jc(num - 1):1;  //如果num>0则返回num *Jc(num - 1),否则返回1
        }
    }
    class excutejiecheng  
    {
        static void Main(string[] args)
        {
            jiecheng n = new jiecheng();
            int result = n.Jc(Convert.ToInt16(Console.ReadLine()));
            Console.WriteLine("result is {0}",result);
            Console.ReadKey();
        }
    }}

上面是阶乘的递归算法,其中判断条件如果  num>0  则返回  num *Jc(num - 1) ,否则返回  1

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69904691/viewspace-2339559/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 贝叶斯
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2019-01-05

  • 博文量
    2
  • 访问量
    2009

最新文章