c++
#include "stdafx.h"
#include<iostream>
#include<stdio.h>
using namespace std;
int terms[30];//保存递归过程中的分解项
int N;//待分解的整数
int counts;//记录当前已输出的结果数
void search(int remainder, int start, int nterm)
{
int i;
if (remainder == 0)
{
counts++;
if (counts % 4 != 1)
{
cout << ";";
}
printf("%d=%d", N, terms[0]);
for (i = 1; i < nterm; i++)
{
printf("+%d", terms[i]);
}
if (counts % 4 == 0)
cout << endl;
}
else
{
for (i = start; i <=remainder; i++)
{
terms[nterm] = i;
search(remainder - i, i, nterm + 1);
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
cin >> N;
counts = 0;
search(N, 1, 0);
if (counts % 4 != 0)
cout << endl;
system("pause");
return 0;
}