【发布时间】:2014-05-18 04:05:45
【问题描述】:
您好,我很难让数组在函数中工作。我不断收到这个错误,称为 C2664 "void ranNumPerm_10(int)' : cannot convert argument 1 from 'int [10]' to 'int'" 我不明白如何解决它...
函数ranNumPerm_10(int):
void ranNumPerm_10(int bubble_1[])
{
int oneRandno;
int haveRand[ARRAY_SIZE_1] = { 0 };
for (int i = 0; i < ARRAY_SIZE_1; i++)
{
do
{
oneRandno = rand() % ARRAY_SIZE_1;
} while (haveRand[oneRandno] == 1);
haveRand[oneRandno] = 1;
bubble_1[i] = oneRandno;
}
return;
}
这个程序是一个未完成的程序,将使用冒泡、选择、插入排序算法。我似乎还无法填充数组。我正在尝试通过成为“随机数排列生成器”来创建一个函数,以便每个数字都是随机的,并且没有数字重复它自己。我可以使用一些帮助来使此代码正常工作并解决错误 C2664。
完整代码:
#define _CRT_SECURE_NO_WARNINGS
#define ARRAY_SIZE_1 10
#include <stdio.h>
#include <stdlib.h>
void ranNumPerm_10(int bubble_1);
int main(void)
{
//Declarations
int bubble_1[ARRAY_SIZE_1];
//Bubble population @ 10
ranNumPerm_10(bubble_1);
for (int i = 0; i < ARRAY_SIZE_1; i++)
{
printf("%d\n", bubble_1[i]);
}
printf("Array population test...\n");
return 0;
}
void ranNumPerm_10(int bubble_1[])
{
int oneRandno;
int haveRand[ARRAY_SIZE_1] = { 0 };
for (int i = 0; i < ARRAY_SIZE_1; i++)
{
do
{
oneRandno = rand() % ARRAY_SIZE_1;
} while (haveRand[oneRandno] == 1);
haveRand[oneRandno] = 1;
bubble_1[i] = oneRandno;
}
return;
}
【问题讨论】:
标签: c arrays function random permutation