输入M=6要求输出6=6,6=5+1,6=4+2,6=4+1+1.。。。。6=1+1+1+1+1+1。。
#include <stdio.h>#include <stdlib.h>
int main()
{
int M;
int *a, c = 0;
int n, s, i;
printf("Input Number:");
scanf("%d", &M);
a = malloc(sizeof(int) * M); /*这句什么意思,怎么理解?*/
n = s = M;
while(c < M)
{
for(i = s; n; i--)
while(n >= i)
{
a[c++] = i;
n -= i;
}
printf("%d=%d", M, a[0]);
for(i = 1; i < c; i++)
printf("+%d", a[i]);
printf("\n");
if(c < M)
{
for(i = c - 1; a[i] == 1; i--)
n++;
n += a[i];
s = a[i] - 1;
c = i;
}
}
return 0;
}
求一个用递归做的代码!