#include
#include
using namespace std;
void fun(int a[],int n,int m)
{
cout<
if(n==m)
{
int j;
for(j=0;j
{
cout<
}
cout<
}
else
{
for(int i=n;i
{
int temp;
temp=a[i];a[i]=a[n];a[n]=temp;
fun(a,n+1,m);
temp=a[i];a[i]=a[n];a[n]=temp;
}
}
}
int main()
{
int n,i,*a;
cin>>n;
a=new int[n];
for(i=0;i
a[i]=i+1;
fun(a,0,n);
return 0;
}
运行截图: