题解 | #统计成绩#
统计成绩
https://www.nowcoder.com/practice/cad8d946adf64ab3b17a555d68dc0bba
#include <stdio.h> #include <stdlib.h> int main(void) { int n; scanf("%d", &n); double *grades = (double *) malloc(sizeof(double) * n); //在堆区创建了一个动态数组 int i; double min, max, sum; for(i = 0; i < n; i++){ scanf("%lf", &grades[i]); } min = max = grades[0]; sum = 0; for(i = 0; i < n; i++){ if(grades[i] < min){ //更新最小值 min = grades[i]; } if(grades[i] > max){ //更新最大值 max = grades[i]; } sum += grades[i]; } printf("%.2f %.2f %.2f\n", max, min, sum / n); free(grades); return 0; }
#猹的刷题生涯#