国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

求任意數(shù)的階層(遞歸方法)

2023-01-29 18:44 作者:此城過客  | 我要投稿

static int F(int input)

{

? ? ? ? if (input == 1)

? ? ? ? { return 1; }//沒有這兩行是不行的。

? ? ? ? return input * F(input - 1);? ? ? ??

}

static void Main(string[] args)

{

? ? ? ? int n = Convert.ToInt32(Console.ReadLine());

? ? ? ? Console.WriteLine(F(n));? ? ? ?

}

======================================================

普通方法對比:

static int F(int input)

{

? ? ? ??int sum = 1;

? ? ? ? for (int j = 1; j < input + 1; j++)

? ? ? ??{ sum *= j; }

? ? ? ??return sum;

}

static void Main(string[] args)

{

? ? ? ? ?int n = Convert.ToInt32(Console.ReadLine());

? ? ? ? ?int n1 = F(n);

? ? ? ? ?Console.WriteLine(n1);

}


求任意數(shù)的階層(遞歸方法)的評論 (共 條)

分享到微博請遵守國家法律
宝鸡市| 油尖旺区| 萨嘎县| 图木舒克市| 右玉县| 南涧| 新闻| 屏东市| 开原市| 长兴县| 东城区| 顺平县| 周口市| 横山县| 保亭| 库尔勒市| 清丰县| 信阳市| 弋阳县| 华安县| 丹阳市| 苏尼特右旗| 枣强县| 温泉县| 略阳县| 襄樊市| 泗水县| 将乐县| 逊克县| 南开区| 泸西县| 永顺县| 峡江县| 盘山县| 梧州市| 延寿县| 潍坊市| 中西区| 河间市| 通海县| 托克托县|