回复 40楼 SunshineGirl
哦哦 下标肯定是连续的 但是数组怎么手动得到?
风回小院庭芜绿,柳眼春相续
#include <stdio.h> #include <string.h> int a[] = {1, 2, 3, 4, 5}; void recursion(int* combination, int m, int n, int begin, int depth); int main(void) { int m = sizeof(a) / sizeof(a[0]); int n = 2; int* combination = (int*)malloc(sizeof(int) * m); recursion(combination, m, n, 1, 1); getchar(); return 0; } void recursion(int* combination, int m, int n, int begin, int depth) { int i, j; for (i = begin; i <= m; i++) { combination[depth] = i; if (depth == n) { for (j = 1; j <= n; j++) { printf("%d ", a[combination[j]-1]); } printf("\n"); } else { recursion(combination, m, n, i+1, depth+1); } } }