#include<stdio.h>
int stack[100];
int top;
int total,n;
void dfs(int index)
{
int i;
if(total==n)
{
printf("%d=",n);
for(i=0;i<top-1;i++)
printf("%d+",stack[i]);
printf("%d\n",stack[top-1]);
}
if(total>n )
return ;
for(i=index;i>=1;i--)
{
total+=i;
stack[top++]=i;
dfs(i);
total-=i;
stack[--top];
}
}
void main()
{
while(scanf("%d",&n)!=EOF)
{
top=0;
total=0;
dfs(n-1);
}
}
C语言 递归拆分数字
最新推荐文章于 2023-02-15 10:14:56 发布