- 865 名前:デフォルトの名無しさん mailto:sage [2008/02/01(金) 23:40:39 ]
- >>858
#include<stdio.h> #include<stdlib.h> void get_combination(int num, int chosenCnt); int *numary; int n, c; int main(int argc, char *argv[]){ if(argc != 3) return 1; n = atoi(argv[1])-1; c = atoi(argv[2]); if((numary = (int*)calloc(sizeof(int), c)) == NULL) return 1; get_combination(0, 1); free(numary); return 0; } void get_combination(int num, int chosenCnt){ int i; if(chosenCnt > c){ for(i=0; i < c; i++) printf(" %d", numary[i]); putchar('\n'); return; } for(i=num; i <= n; i++){ numary[chosenCnt-1] = i; get_combination(i+1, chosenCnt+1); } }
|

|