Rumah > Soal Jawab > teks badan
using namespace std;
void swap(int list[], int m, int n)
{
int temp;
temp = list[m];
list[m] = list[n];
list[n] = temp;
}
void recurrence(int list[],int i, int j)
{
if (i == j)
{
for (int t = 0; t <= j; t++)
{
cout << list[t];
}
cout << endl;
}
else
{
for (int t = i; t <= j; t++)
{
swap(list, i, t);
recurrence(list, i + 1, j);
swap(list, i, t);
}
}
}
int main()
{
/*
int b;
cout << "请输入总的个数:\n" << endl;
cin >> b;
int *a = new int[b];
recurrence(a, 0, b-1);
delete[]a;
*/
int *a;
int b;
cout << "请输入总的个数:\n" << endl;
cin >> b;
a = (int*)malloc(b*sizeof(int));
recurrence(a, 0, b - 1);
system("pause");
return 0;
}
我的运行结果是一串的负数
PHP中文网2017-04-17 13:07:24
a = (int)malloc(bsizeof(int));
for (int i = 0; i < b; i++)
{
a[i] = i + 1;
}
recurrence(a, 0, b - 1);
请插入这段