Find m combinations from a N set

来源:互联网 发布:金十网数据官网 编辑:程序博客网 时间:2024/06/05 00:51

Using a recursion method, choose one number first and choose another from the set N -1 till m=0


#include <stdlib.h>int a[10]={1,2,3,4,5,6,7,8,9,0};int count=0;void findCombination(int a[], int inLen, int m, int out[], int outLen){if(m == 0){int j = outLen - 1;for(; j >= 0; j--){printf("%d ", out[j]);}printf("\n");count++;return;}int i;for(i = inLen; i >= m; i--){out[m-1] = a[i-1];findCombination(a,i-1, m-1, out, outLen);}}int main(){int out[3];findCombination(a, 10, 3, out, 3);printf("All combinations count is: %d", count);}


原创粉丝点击