#include <stdio.h> int arrayAverage(int a[], int count); int arrayMax(int a[],int count); int arrayMin(int a[],int count); int main() { //1> 提示输入5个学生的成绩,算出平均分、最高分、最低分,然后输出 int arry[5]; for (int i=0; i<5; i++) { printf("please %d number\n",i+1); scanf("%d",&arry[i]); } int length=sizeof(arry)/sizeof(int); int ave=0,max=0,min=0; ave=arrayAverage(arry,length); max=arrayMax(arry,length); min=arrayMin(arry,length); printf("平均成绩为%d,最大成绩为%d,最小成绩为%d\n",ave,max,min); return 0; } int arrayAverage(int a[], int count) { int sum = 0; for (int i = 0; i < count; i++) { sum += a[i]; } int average = sum / count; return average; } int arrayMax(int a[],int count) { int max=a[0]; for (int i=0; i<count; i++) { if (max<a[i]) { max=a[i]; } } return max; } int arrayMin(int a[],int count) { int min=a[0]; for (int i=0; i<count; i++) { if(min>a[i]) { min=a[i]; } } return min; }
时间: 2024-10-13 22:28:40