对某个数分解

 1 #include<stdio.h>
 2 #include<conio.h>
 3 int result[100];
 4 
 5 void split(int n, int k, int c)
 6 {
 7     if (k == 0) return;
 8     if (n == k)
 9     {
10         result[c]=k;
11         for (int i = 0; i <=c; i++)
12             printf("%d ",result[i]);
13         printf("\n");  
14         if (k == 1)return;
15     }
16     for (int i = k; i >= 1; i--)
17     {
18         result[c] = i;
19         split(n - i, i < n - i ? i : n - i, c + 1);
20     }
21 }
22 
23 int main()
24 {
25     split(6, 5, 0);//对6分解 
26     getch();
27     return 0;
28 }

posted @ 2013-05-02 11:01  Please Call me 小强  阅读(187)  评论(0编辑  收藏  举报