Pagini recente » Cod sursa (job #2159474) | Cod sursa (job #3217450) | Cod sursa (job #2552607) | Cod sursa (job #813558) | Cod sursa (job #194391)
Cod sursa(job #194391)
/*
Cristi Balas,
Facultatea de Matematica si Informatica, Universitatea Bucuresti
cristi8 [at] gmail.com
*/
#include <stdio.h>
int n;
int used[10];
int stiva[10];
void afiseaza() {
int i;
for(i = 1; i <= n; i++)
printf("%d ", stiva[i]);
printf("\n");
}
void back(int nivel)
{
if(nivel > n)
afiseaza();
else
{
for(stiva[nivel] = 1; stiva[nivel] <= n; stiva[nivel]++)
if(!used[ stiva[nivel] ])
{
used[ stiva[nivel] ] = 1;
back(nivel + 1);
used[ stiva[nivel] ] = 0;
}
}
}
int main()
{
freopen("permutari.in", "r", stdin);
freopen("permutari.out", "w", stdout);
scanf("%d", &n);
back(1);
return 0;
}