#include <stdio.h>
#include <stdlib.h>
int n,k,a[10];
long count = 0;
void perm2(int j)
{
int i,p,t;
if(j == k)
{
for(i = k;i <= n; i++)
{
count ++;
t = a[k]; a[k] = a; a =t;
for(p = 1; p <= k; p++)
{
printf("%1d",a[p]);
}
printf(" ");
t = a[k]; a[k] = a; a = t;
if(count % 5 == 0)
{
printf("\n");
}
}
return;
}
for(i = j; i <= n; i++)
{
t = a[j]; a[j] = a; a = t;
perm2(j+1);
t = a[j]; a[j] = a; a = t;
}
}
mian()
{
int i;
printf("\nEntery n,k(k <= n): \n");
scanf("%d%d",&n,&k);
for (i = 1; i <= n; i++)
{
a = i;
}
perm2(1);
system("pause");
return 0;
}
1、选排列\第一题.cpp In function 'void perm2(int)':
1、选排列\第一题.cpp [Error] invalid conversion from 'int*' to 'int' [-fpermissive]
1、选排列\第一题.cpp [Error] incompatible types in assignment of 'int' to 'int [10]'
1、选排列\第一题.cpp [Error] invalid conversion from 'int*' to 'int' [-fpermissive]
1、选排列\第一题.cpp [Error] incompatible types in assignment of 'int' to 'int [10]'
1、选排列\第一题.cpp [Error] invalid conversion from 'int*' to 'int' [-fpermissive]
1、选排列\第一题.cpp [Error] incompatible types in assignment of 'int' to 'int [10]'
1、选排列\第一题.cpp [Error] invalid conversion from 'int*' to 'int' [-fpermissive]
1、选排列\第一题.cpp [Error] incompatible types in assignment of 'int' to 'int [10]'
1、选排列\第一题.cpp In function 'int mian()':
1、选排列\第一题.cpp [Error] incompatible types in assignment of 'int' to 'int [10]'
数据类型出错,你的a定义是数组int a【10】,a相当于是一个指针,赋值的时候,a = i,相当于把一个变量赋值给指针了,应该改成a【i】 = i这种赋值方式
a定义成了一个数组, 在 a[k] = a; a = t; 这俩句 a被当成一个变量使用了。数据类型不符合。
多谢,多谢,谢谢大佬。