Pagini recente » Istoria paginii utilizator/toma_ariciu | Istoria paginii runda/aa | Concursuri Virtuale | Monitorul de evaluare | Cod sursa (job #145280)
Cod sursa(job #145280)
#include <stdio.h>
int n,k;
int fol[10];
void afisare()
{
int i,j;
for (i=1; i<=n; i++)
for (j=1; j<=n; j++)
if (fol[j]==i)
{
printf("%d ",j);
break;
}
printf("\n");
}
void back()
{
int i;
if (k>n)
{
afisare();
return;
}
for (i=1; i<=n; i++)
if (fol[i]==0)
{
fol[i]=k;k++;
back();
k--;fol[i]=0;
}
}
int main()
{
freopen("permutari.in","r",stdin);
freopen("permutari.out","w",stdout);
scanf("%d",&n);
k=1;
back();
return 0;
}