题解 | #统计成绩#c语言动态内存管理版
统计成绩
https://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba
#include <stdio.h> #inlcude<stdlib.h> int main() { int n = 0; scanf("%d", &n); double* arr = (double*)realloc(NULL, n * sizeof(double));//动态内存管理,手动调整arr的内存大小 for (int i = 0; i < n; i++) { scanf("%lf", &arr[i]);//挨个赋值 } double aver, max, min; max = arr[0]; min = arr[0]; double sum = 0; for (int i = 0; i < n; i++) { if (arr[i] > max) { max = arr[i]; } if (arr[i] < min) { min = arr[i]; } sum += arr[i]; } aver = (double)(sum / n); printf("%.2lf %.2lf %.2lf", max, min, aver); return 0; }