Skip to content

Commit 74af0c6

Browse files
committed
20190331
1 parent 4ba7b7c commit 74af0c6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

整数划分(递归示例).cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
void go(int n, int steps)
5+
{
6+
if (n == 0)
7+
{
8+
return;
9+
}
10+
cout << n;
11+
if (steps < n && steps != 0)
12+
{
13+
cout << " + " << steps;
14+
}
15+
else for(int i = 0; i < steps; i++)
16+
{
17+
cout << " + 1";
18+
}
19+
cout << endl;
20+
go(n - 1, steps + 1);
21+
}
22+
int main()
23+
{
24+
int n;
25+
cin >> n;
26+
go(n, 0);
27+
system("pause");
28+
return 0;
29+
}

0 commit comments

Comments
 (0)