by api · 3y ago · 0 comments
This model seems roughly on par with GPT-3, maybe GPT-3.5 in some cases.
> Write a function to compute the maximum, minimum, and average of an array of doubles in C.
Here is an example function in C that computes the maximum, minimum, and average of an array of doubles:
```c void compute_statistics(double arr[], int n) { double max = arr[0]; double min = arr[0]; double sum = 0.0; for (int i = 1; i < n; i++) { if (arr[i] > max) { max = arr[i]; } else if (arr[i] < min) { min = arr[i]; } sum += arr[i]; } double avg = sum / n; printf("Maximum: %.2f", max); printf("Minimum: %.2f", min); printf("Average: %.2f", avg); } ```
To use this function, simply call it with the array of doubles and its length as arguments. For example:
```c double arr[] = {1.0, 2.5, 3.0, 4.0, 5.0}; int n = sizeof(arr) / sizeof(arr[0]); compute_statistics(arr, n); ```
This will output:
``` Maximum: 5.00 Minimum: 1.00 Average: 3.00 ```
Here are some simple logic questions:
> Compute the sum of an array of 512 elements with each element having the value 2.
The sum of an array of 512 elements with each element having the value 2 is 1024.
> Compute the sum of an array of 512 elements with each element having the value 3.
The sum of an array of 512 elements with each element having the value 3 is 1536.
Not bad.
No comments yet.