length's type.

Gary Chike chikega at gmail.com
Wed Feb 7 20:08:24 UTC 2024


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

The output wasn't quite right. So I tweaked it a bit:
```c
long sumArray(long arr[], size_t size) {
     long 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(a, aLength) / aLength;

     printf("Average: %.2lf\n", c); // -2500.00

     return 0;
}

```



More information about the Digitalmars-d-learn mailing list