Pagini recente » Cod sursa (job #1411252) | Cod sursa (job #2926830) | Cod sursa (job #2975566) | Cod sursa (job #3156934) | Cod sursa (job #144729)
Cod sursa(job #144729)
#include <stdio.h>
int n, i, v[10], uz[10];
void gen(int);
int main()
{
fscanf(fopen("permutari.in", "r"), "%d", &n);
freopen("permutari.out", "w", stdout);
gen(1);
fclose(stdout);
return 0;
}
void gen(int x)
{
if (x>n)
{
for (int i=1; i<=n; i++) printf("%d ", v[i]); printf("\n");
}
else
for (int i=1; i<=n; i++)
if (!uz[i])
{
v[x]=i;
uz[i]=1;
gen(x+1);
uz[i]=0;
v[x]=0;
}
}