#include <stdio.h> #include <stdbool.h> void PrintAll(int a[], int nBegin, int nEnd, int nCount, char* szPre){ if(nCount==1){ for(int i=nBegin; i<=nEnd; i++){ printf("%s%d ", szPre, a[i] ); } printf("\n"); }else{ for(int i=nBegin; i<=nEnd-nCount+1; i++){ char szBuf[10]= {0}; sprintf(szBuf, "%s%d", szPre,a[i] ); PrintAll(a, i+1, nEnd, nCount-1, szBuf); } } } int main(){ int a[] = {1,2,3,4,5,6}; PrintAll(a, 0, 5, 3, ""); return 1; }