On Wednesday, 7 February 2024 at 19:20:12 UTC, Gary Chike wrote:

I just had to transcribe this to C just for grins :D
```c
#include <stdio.h>

int sumArray(int arr[], size_t size) {
    int total = 0;
    for (size_t i = 0; i < size; ++i) {
        total += arr[i];
    }
    return total;
}

int main(void) {
    long a[] = {-5000, 0};
    size_t aLength = sizeof(a) / sizeof(a[0]);

    double c = (double)sumArray((int*)a, aLength) / aLength;
    printf("Average: %.2lf\n", c); // -2500 <- correct output

    return 0;
}
```


Reply via email to