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