#include #include void gen(char *head, char *a, int k) { char myHead[10]; char *c, *e; if ( k == 0 ) { printf(">> %s\n", head); return; } strcpy(myHead, head); for ( e = myHead; *e != '\0'; e++ ); *(e+1) = '\0'; for ( c = a; *c != '\0'; c++ ) { *e = *c; gen(myHead, c+1, k-1); } } int main(int argc, char **argv) { char a[] = "abcde"; char head[] = ""; int k = 3; gen(head, a, k); }