标签:技术 习题 sum 生成 turn max alt ++ span
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main(void) 5 { 6 int n; 7 double *p; 8 scanf("%d", &n); 9 10 p = (double *)calloc(n, sizeof(double)); 11 for (int i = 0; i < n; i++) 12 { 13 scanf("%lf", p + i); 14 } 15 16 double sum = 0; 17 int max_index = 0; 18 int min_index = 0; 19 20 for (int i = 0; i < n; i++) 21 { 22 sum = sum + p[i]; 23 if (p[i] > p[max_index]) 24 { 25 max_index = i; 26 } 27 if (p[i] < p[min_index]) 28 { 29 min_index = i; 30 } 31 } 32 33 printf("average = %.2f\n", sum / n); 34 printf("max = %.2f\n", p[max_index]); 35 printf("min = %.2f\n", p[min_index]); 36 37 free(p); 38 return 0; 39 }
标签:技术 习题 sum 生成 turn max alt ++ span
原文地址:https://www.cnblogs.com/2018jason/p/12073801.html