我编写了这个程序,它在整数数组中找到最大元素的索引。由于某种原因,当我尝试编译它时出现以下错误。关于我的代码有什么问题的任何想法?我似乎找不到任何东西。
part1.c:9: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
part1.c: In function ‘main’:
part1.c:13: warning: implicit declaration of function ‘largest’
part1.c: At top level:
part1.c:20: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
make: *** [part1] Error 1
我的代码:
// Program that finds the largest element in an array of integers
#include <stdio.h>
// Main body
// Create and initialise a one-dimensional array of integers
#define ARRAY_SIZE 10
int largest(int array, int ARRAY_SIZE);
int main(int argc, char** argv)
{
int array [ARRAY_SIZE] = { 5, 1, 2, 8, 12, 9, 0, 4, 52, 91 };
int maxIndex = largest(array, ARRAY_SIZE);
printf("%d", maxIndex);
}
// largest - function
// takes (array,length) -> returns the index of the largest element in the array
int largest(int array, int ARRAY_SIZE)
{
int maxIndex;
for(int index = 0; index < 10; index++)
{
if array[i] > array[i+1]
i = maxIndex;
}
return maxIndex;
}