学习一下递归!- void resolve(int n, int m)
- {
- int i;
- if(n == 0)
- output(m);
- else
- {
- for(i = n; i >= 1; i--)
- if(m==0 || i<=a[m-1])
- {
- a[m] = i;
- resolve(n-i, m+1);
- }
- }
- }
- int main(void) //整数划分,输出划分后的结果
- {
- int n, m = 0;
- printf("Please input a number: ");
- scanf("%d", &n);
- resolve(n, m);
- return 0;
- }
复制代码
|