基于有递推公式的:
1、递归 个人认为比较好的
2、递归转化为非递归 点击打开链接
不基于有递推公式的:
3、非递归
4、#include <iostream>
using namespace std;
main()
{
int i,j,n,t;
cout<<"请输入n的值:";
cin>>n;
cout<<n<<endl;
for(i=n-1;i>0;i--)
{
for(j=n-i;j>0;j--)
{
if(j>i){
continue;
}else
{
if(j==n-i)
cout<<i<<"+"<<j<<" ";
else
{
t=n-(i+j);
if(t==j && t==i && i==j)
cout<<i<<"+"<<j<<"+"<<t<<" ";
cout<<i<<"+"<<j;
while(t>0)
{
cout<<"+1";
--t;
}
cout<<" ";
}
}
}
cout<<endl;
}
}