void x(void); void perm(char * a, int n){ // This routine permutes the n characters starting at a and for // each permutation, calls x. // The characters are left as they were found. if (n < 2) x(); else {char t = *a; int j=n; while(j--) { char u = *(a+j); *a = u; *(a+j) = t; perm(a+1, n-1); *(a+j) = u;} *a = t;}} // Demo and test: #include #include char q[8]; int main () {strcpy(q, "abcdefg"); perm(q, 7); return 0;} void x() {static int c=0; if(!(c--)) {printf("\n"); c=6;} printf("%s ", q);}