#include <stdio.h>
int maxScore(int array[], int length);
int minScore(int array[], int length);
double evenScore(int array[], int length);
int main(){
int score[5] = {0};
int i = 1;
while (i <= 5) {
printf("请输入个学生的分数:\n>");
scanf("%d",&score[i]);
++i;
}
int len = sizeof(score) / sizeof(int);
int maxscore = maxScore(score, len);
printf("五个学生中最高分是%d\n",maxscore);
int minscore = minScore(score, len); //最高分是对的,最低分和平均分是错误的,自己实在找不出来
printf("五个学生中最低分是%d\n",minscore);
double evenscore = evenScore(score, len);
printf("五个学生的平均分是%f\n",evenscore);
return 0;
}
int maxScore(int array[], int length){
int max = array[0];
for(int i = 0; i < length; i++){
if(max < array[i]){
max = array[i];
}
}
return max;
}
int minScore(int array[], int length){
int min = array[0];
for(int i = 0; i < length; i++){
if(min > array[i]){
min = array[i];
}
}
return min;
}
double evenScore(int array[], int length){
double even = 0;
int sum = 0;
for(int i = 0; i < length; i++){
sum += array[i];
}
printf("%d",sum);
even = sum / length;
return even;
} |
|