BUPT-homework/semester1/pset13/1-2-GetScore.c

48 lines
851 B
C
Raw Normal View History

2021-12-09 17:26:31 +08:00
#include <stdio.h>
#include <stdlib.h>
int *create(int n);
void cal(int *array, int size);
int main() {
int *array, n, i;
scanf("%d", &n);
array = create(n);
cal(array, n);
for (i = 0; i < n; i++) {
printf("%d", *(array + i));
if (i == n - 1)
printf("\n");
else
printf(" ");
}
free(array);
return 0;
}
/* 请在这里填写答案 */
int *create(int n) { return malloc(n * sizeof(int)); }
void cal(int *array, int size) {
for (int i = 0; i < size; i++) {
scanf("%d", &array[i]);
}
int sum = 0, max = array[0], min = array[0];
for (int i = 0; i < size; i++) {
sum += array[i];
if (array[i] > max)
max = array[i];
else if (array[i] < min)
min = array[i];
}
printf("%d\n", sum);
printf("%.2f\n", sum / (float)size);
printf("%d\n", max);
printf("%d\n", min);
}