new here :)
double average(int arr[]) {
int total = 0;
int i;
int count = 0;
double avg;
int len = sizeof arr / sizeof arr[0];
printf("%i\n", len);
for (i=0; i<len; i++)
{
total += arr[i];
count += 1;
}
avg = (double) total / count ;
return avg; }
int main() {
int array1[5] = {150, 20, 20, 40, 190};
printf("%f", average(array1));
The function average(int arr[]) aims to find the average of all elements in the array, which is then called in the main function below
Just wanted to ask why the sizeof array1 / sizeof array1[0] is not returning the correct length of my given array (which in this case = 5). It instead returns 2.
Hope you can help! Thanks in advance! :)