新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
c#中怎么實(shí)現(xiàn)一個階乘遞歸算法-創(chuàng)新互聯(lián)
c# 中怎么實(shí)現(xiàn)一個階乘遞歸算法,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
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
關(guān)于c# 中怎么實(shí)現(xiàn)一個階乘遞歸算法問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道了解更多相關(guān)知識。
本文題目:c#中怎么實(shí)現(xiàn)一個階乘遞歸算法-創(chuàng)新互聯(lián)
URL地址:http://www.ef60e0e.cn/article/dgsohi.html