RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
c#中怎么实现一个阶乘递归算法

c# 中怎么实现一个阶乘递归算法,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

创新互联主营东兴网站建设的网络公司,主营网站建设方案,app软件开发,东兴h5微信小程序开发搭建,东兴网站营销推广欢迎东兴等地区企业咨询

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

关于c# 中怎么实现一个阶乘递归算法问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


网站名称:c#中怎么实现一个阶乘递归算法
URL分享:http://sczitong.cn/article/gpodjo.html