數組的案例:分數
#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