入口点
1
using System;
2![]()
3
namespace 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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

实现的类
1
using System;
2![]()
3
namespace 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![]()

2

3

4



5


6

7

8

9



10



11


12

13

14

15


16

17

18

19


20

21

22

23

24



25


26

27


28

29

30

31



32

33

34

35

36


37

38

39



40

41

42


43

44

45


46

47

48

49

50

51



52

53



54

55


56

57



58

59

60

61


62

63



64

65

66

67

68

69

70

71
