#include <stdio.h>
#define N 5
int main(int argc, char** argv, char** env)
{
int stack[N], pos;
int i,j,k,m,n,sum;
for(i=1;i<=N;i++)
{
for(j=0;j<N;j++)stack[i]=0;
pos=0;sum=0;
for(j=1;j<=N;j++)
{
stack[pos++]=j;
sum+=j;
if(pos==i)
{
for(k=0;k<pos;k++)
{
printf("%3d+",stack[k]);
}
printf("\b=%3d\n",sum);
pos--;
sum-=j;
j=stack[pos];
if(j==N && pos>=1)
{
pos--;
sum-=stack[pos];
j=stack[pos];
}
continue;
}
else if(j==N && pos>1)
{
pos--;
sum-=stack[pos];
j=stack[--pos];
sum-=stack[pos];
continue;
}
}
}
return 0;
}