Pagini recente » Cod sursa (job #2127385) | Cod sursa (job #2389330) | Cod sursa (job #482917) | Cod sursa (job #1894931) | Cod sursa (job #1017813)
#include<cstdio>
int st[9], n, apare[9];
void afisare( FILE *g ) {
for( int i = 1 ; i <= n ; ++i )
fprintf( g, "%d ", st[i] );
fprintf( g, "\n" );
}
/*int valid( int niv ) {
for( int i = 1 ; i < niv ; ++i )
if( st[i] == st[niv] )
return 0;
return 1;
}*/
void perm( int niv, FILE *g ) {
if( niv == n + 1 )
afisare( g );
else
for( int i = 1 ; i <= n ; ++i )
{
if( apare[i] == 0 )
{
apare[i] = 1;
st[niv] = i;
perm( niv + 1, g );
apare[i] = 0;
}
}
}
int main () {
FILE *f, *g;
f = fopen( "permutari.in", "r" );
g = fopen("permutari.out", "w" );
fscanf( f, "%d", &n );
perm( 1, g );
fclose( f );
fclose( g );
return 0;
}