找出某个正整数可能被表示成n个连续的正整数之和.
如 11 = 5+6
代码
1
private
void
Calc(
int
iValue)
2 {
3 int tValue = iValue;
4 int MidValue = iValue / 2 + 1 ;
5 for ( int i = 1 ; i < MidValue; i ++ )
6 {
7 fun(i, i, iValue);
8 }
9 }
10
11 private void fun( int start, int end, int cValue)
12 {
13 if (cValue > end)
14 {
15 fun(start, end + 1 , cValue - end);
16 }
17 else if (cValue == end) // 输出
18
19 {
20 for ( int j = start; j < cValue + 1 ; j ++ )
21 {
22 Response.Write(j.ToString() + " == " );
23 }
24 }
25 }
26
27
2 {
3 int tValue = iValue;
4 int MidValue = iValue / 2 + 1 ;
5 for ( int i = 1 ; i < MidValue; i ++ )
6 {
7 fun(i, i, iValue);
8 }
9 }
10
11 private void fun( int start, int end, int cValue)
12 {
13 if (cValue > end)
14 {
15 fun(start, end + 1 , cValue - end);
16 }
17 else if (cValue == end) // 输出
18
19 {
20 for ( int j = start; j < cValue + 1 ; j ++ )
21 {
22 Response.Write(j.ToString() + " == " );
23 }
24 }
25 }
26
27