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