#include<stdio.h>
#include<stdlib.h>
void fun( int n )
{ int j, b, c, m, flag=0;
for (b=1; b<=n/2; b++) //b=1开始至n/2,尝试有1开始的累加之和为n
{
m = n; //每次while循环,都重新为m赋值
c = b;
while (m !=0 && m>=c)
{
m = m - c; c++;
}
if ( m==0)
{ printf("%d=", n);
for (j=b; j<c-1; j++) printf( "%d+", j );
printf("%d\n", j);
flag=1;
}
}
if(flag==0)
printf("不能分解\n");
}
int main()
{ int n;
printf("请输入一个整数 : "); scanf("%d", &n);
fun(n);
system("pause");
return 0;
}