p95 输入n个数,输出这n个数的所有排列

论坛 期权论坛 脚本     
匿名技术用户   2020-12-28 13:23   18   0

// 多项式求值.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
using namespace std;

void perml(int m,int P[],int n)
{
int change,change1;
if(m==n)
{
for(int i=1;i<=n;i++)
{
cout<<P[i]<<" ";
}cout<<endl;
}else
{
for(int j=m;j<=n;j++)
{
change=P[j];
P[j]=P[m];
P[m]=change;

perml(m+1,P,n);
change1=P[j];
P[j]=P[m];
P[m]=change1;
}
}

}


int main(int argc, char* argv[])
{
int num;
int ch[100];
cout<<"请输入数的个数"<<endl;
cin>>num;
cout<<"请输入"<<num<<"个数"<<endl;
for(int i=1;i<=num;i++) cin>>ch[i];
perml(1,ch,num);


return 0;
}

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP