首页 > 其他 > 详细

用各种语言写出n!的算法

时间:2014-03-12 20:16:01      阅读:490      评论:0      收藏:0      [点我收藏+]

写出n!的算法

C#    

bubuko.com,布布扣
 1  class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             Console.WriteLine("请输入一个数!");
 6             int input =Convert.ToInt32(Console.ReadLine());
 7            int result= GetFactorialValue(input);
 8            Console.WriteLine("{0}的阶乘的值是:{1}", input, result);
 9            Console.ReadKey();
10         }
11         /// <summary>
12         /// 获得阶乘的值
13         /// </summary>
14         /// <param name="input"></param>
15         /// <returns></returns>
16         private static int GetFactorialValue(int input)
17         {

18                 if (input == 0 || input == 1)
19                 {
20                     return 1;
21                 }
22                 return input*GetFactorialValue(input - 1);
23         }
24     }
View Code


java

 

vb

 

c

 

 

研究中.....

会的就在评论吧,欢迎你们的参与,谢谢!

用各种语言写出n!的算法,布布扣,bubuko.com

用各种语言写出n!的算法

原文:http://www.cnblogs.com/zlp520/p/3597011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!