HansJack

HansJack

Case of p120 array: fractions

Array Example: Scores

#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("The report card for everyone is as follows:");

	for (uint32_t index = 0; index < STUDENT_COUNT; index++) {
	
		printf("Student %" PRIu32 "'s score: %" 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("\nAverage score: %.2f\n", average);
	printf("Highest score: %d\n", max_grade);
	printf("Lowest score: %d\n", min_grade);
	return 0;
}

This article is synchronized by Mix Space to xLog
The original link is https://hansblog.top/posts/study-book/c-p120


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.