p120数组的案例：分数

数组的案例：分数

Copy
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

#define STUDENT_COUNT 5
int main(void)
{

uint32_t grades[STUDENT_COUNT] = { 85, 92, 88, 96, 66 };

uint32_t sum = 0;

uint32_t max_grade = grades[0];

uint32_t min_grade = grades[0];

puts("所有人的成绩单如下：");

for (uint32_t index = 0; index < STUDENT_COUNT; index++) {

printf("学生%" PRIu32 "的成绩：%" PRIu32 "\n", index +1, grades[index]);

sum += grades[index];

if (grades[index] > max_grade) {
max_grade = grades[index];

}

if (grades[index] < min_grade) {
min_grade = grades[index];

}

}

double average = (double)sum / STUDENT_COUNT;

printf("\n平均成绩：%.2f\n", average);
printf("最高成绩：%d\n", max_grade);
printf("最低成绩：%d\n", min_grade);
return 0;
}

此文由 Mix Space 同步更新至 xLog
原始链接为 https://hansblog.top/posts/study-book/c-p120