Pagini recente » Cod sursa (job #1481784) | Cod sursa (job #1986747) | Cod sursa (job #2868249) | Cod sursa (job #2904013) | Cod sursa (job #2870870)
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n,st[10];
bool viz[10];
void afis(int vf)
{
for(int i=1;i<=vf;i++)
fout<<st[i]<<' ';
fout<<'\n';
}
void back(int vf)
{
for(int x=1;x<=n;x++)
{
st[vf]=x;
if(viz[st[vf]]==0)///nu e vizitat
{
viz[st[vf]]=1;
if(vf==n)
afis(vf);
else
back(vf+1);
viz[st[vf]]=0;
}
}
}
int main()
{
fin>>n;
back(1);
return 0;
}