Created
December 23, 2021 15:47
-
-
Save Tony363/8e9fe36aa04acb4d44c0b3d26974c962 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void proc(int a[], int n, int *min_p, int *max_p, double *avg_p) | |
{ | |
int min, max, avg, sum = 0; | |
for (int i = 0; i < n; i++) | |
{ | |
if (i == 0) | |
{ | |
min = max = a[i]; | |
} | |
else | |
{ | |
if (a[i] < min) | |
{ | |
min = a[i]; | |
} | |
if (a[i] > max) | |
{ | |
max = a[i]; | |
} | |
} | |
sum += a[i]; | |
} | |
*avg_p = (double)sum / (double)n; | |
*min_p = min; | |
*max_p = max; | |
} | |
int main(int argc, char **argv) | |
{ | |
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
int n = sizeof(a) / sizeof(a[0]); | |
int min, max; | |
double avg; | |
proc(a, n, &min, &max, &avg); | |
printf("min: %d, max: %d, avg: %f\n", min, max, avg); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment