在一个排列好的列表中写下每个球员进球数的程序
C语言代码中的排序数组在Visual Studio中显示错误“未计算为常量”。
int main() {
int i,temp,swaped;
int howmany = 10;
int goal[howmany];
for (i = 0;i <= howmany;i++) {
goal[i] = (rand() % 40)+1;
}
printf("orignal list");
for (i = 0;i <= howmany;i++) {
printf("%d \n", goal[i]);
}
while (1) {
swaped = 0;
for (i = 0;i < howmany;i++) {
if (goal[i] > goal[i + 1]) {
goal[i] = temp;
goal[i] = goal[i + 1];
goal[i + 1] = temp;
swaped = 1;
}
}
if (swapped == 0) {
break;
}
printf("sorted list");
for (i = 0;i < howmany;i++) {
printf("%d \n", goal[i]);
}
}
_getch();
return 0;
}
最佳答案
Visual Studio 2013有一个非常陈旧的C编译器,即使在这么多年之后,它仍然无法理解C99。所以你需要改变这个:
int howmany = 10;
int goal[howmany];
致:
#define howmany 10
int goal[howmany];
关于c - C语言中的错误排序数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32871245/