//输入1~9之间的数,输出全排列
#include<iostream>
using namespace std;
int n,book[11],array[11];
void dfs(int step)
{
if(step==n+1)
{
for(int i=1;i<=n;i++)
{
printf("%d",array[i]);
}
printf("\n");
return;
}
for(int i=1;i<=n;i++)
{
if(book[i]==0)
{
book[i]=1;
array[step]=i;
dfs(step+1);
book[i]=0;
}
}
return;
}
int main()
{
scanf("%d",&n);
dfs(1);
getchar();getchar();
return 0;
}
03-26
187
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)