|
|
Problème
Trouver toutes les permutations de N dans P
Programme
#define N 3 // nombre de chiffres
#define P 4 // ensemble {0..P-1}, soit P valeurs
char r[N+2];
void next(int c, int u, int j) {
if ( c < N ) {
if ( !(u & (1<<j))) r[c] = j+'0', next(c+1, u| (1<<j), 0);
if ( j != P-1 ) next(c, u, j+1);
} else
printf(r);
}
int main ( void ) {
r[N]='\n';r[N+1]=0x00;
next(0,0,0);
}
|