绿野人

为了好好的活着而活着

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::

入口点

 1using System;
 2
 3namespace CompleteFactorial
 4{
 5    /// <summary>
 6    /// Summary description for Class1.
 7    /// </summary>

 8    class FactorialMain
 9    {
10        /// <summary>
11        /// The main entry point for the application.
12        /// </summary>

13        [STAThread]
14        static void Main(string[] args)
15        {
16            Util.Factorial(100);
17            Console.ReadLine();
18        }

19    }

20}

实现的类

 1using System;
 2
 3namespace CompleteFactorial
 4{
 5    /**//// <summary>
 6    /// Summary description for Util.
 7    /// </summary>
 8    public class Util
 9    {
10        public Util(){}
11        /**//// <summary>
12        /// 定义每个数组存储的最大值
13        /// </summary>
14        const int UNIT=100;
15        /**//// <summary>
16        /// 定义数组的最大位置
17        /// </summary>
18        static int count=1;
19        /**//// <summary>
20        /// 阶乘方法
21        /// </summary>
22        /// <param name="n">输入的阶乘数</param>
23        public static void Factorial(int n)
24        {
25            /**////分配临时空间
26            int[] array=new int[100];
27            /**////初始化数组0位的值
28            array[0]=1;
29            count=1;
30            while(n>0)
31            {
32                Dohandle(array,n);
33                n--;
34            }
35            Console.WriteLine("Count = "+count);
36            /**////打印数据
37            Console.Write("阶乘计算结果 = ");
38            for(int i=count;i>-1;i--)
39            {
40                Console.Write(array[i].ToString("00"));
41            }
42            /**//* 阶乘计算结果 = 933262154439441526816992388562667004907159682643816214685929638952175999932
43                     29915608941463976156518286253697920827223758251185210916864000000000000000000000000 */
44        }
45        /**//// <summary>
46        /// 处理阶乘
47        /// </summary>
48        /// <param name="array">数组</param>
49        /// <param name="n">要乘的数</param>
50        private static void Dohandle(int[] array,int n)
51        {
52            for(int i=count;i>-1;i--)
53            {
54                array[i]*=n;
55                /**////如果超出最大存储的值
56                if(array[i]>UNIT)
57                {
58                    //进位
59                    array[i+1]+=array[i]/UNIT;
60                    array[i]=array[i]%UNIT;
61                    /**////count记住数组最大位置
62                    if(i>=count)
63                    {
64                        count=i+1;
65                    }
66                }
67            }
68        }
69    }
70}
71
posted on 2006-06-21 09:02  绿野人  阅读(1469)  评论(0编辑  收藏  举报