Hi this is one of my questions i have been given to do but i cant get it to compile please help!
question was :
Write a function called arraysum that takes two arguments: an integer array and the number of elements in the array. Have the function return as its result the sum of the elements in the array.
My attempt:
Code:
#include <stdio.h>
int arraysum (int array[], int numberOfElements)
{
int i, sum=0;
for (i =0; i <numberOfElements; ++i)
sum = sum + array[i];
return sum;
}
int main (void)
{
int array1[5] = {15,28,37,26,10};
numberOfElements = 5;
int i, sum =0;
int arraysum (int array[],int numberOfElements);
printf("The sum is %d\n", arraysum(array1,numberOfElements));
return 0;
}