C语言 输入一个整数n,增序输出1,2,3,4.……n的全排列

如输入3,输出123,231,312,321,213,132

第1个回答  2009-11-25
#include <stdio.h>
#define MAX 100
void process(char *c,int n)
{
int i = 0;
while(i < n)
{
printf("%c",c[i]);
i=i+1;
}
printf("\n");
}
void perm(char *list,int n)
{
int k;
char tmp;
int i = n;
int count[MAX];
count[i - 1] = 1;
while(i > 2)
{
i--;
count[i - 1] = 1;
}
process(list,n);
do{
if(count[i - 1] < i)
{
if(i%2 != 0)
k = 1;
else
k = count[i-1];
tmp = list[k - 1];
list[k-1] = list[i-1];
list[i-1] = tmp;
count[i-1] += 1;
i = 2;
process(list,n);
}
else
{
count[i-1] = 1;
i+=1;
}
}
while(i <= n);
}
int main()
{
char c[] = {'a','b','c','d'};
perm(c,4);
return 0;
}
第2个回答  2009-11-25
#include <stdio.h>
main()
{
int n,i;
printf("Input n:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("%d",i);
}本回答被网友采纳
第3个回答  2009-11-25
不会了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网