#include <stdio.h> int main() { int N; // Number of students float sum = 0.0; // Sum of all quiz scores float score; // Variable to store each student's score float average; // Variable to store the average score // Prompt the user to enter the number of students printf("Enter the number of students: "); scanf("%d", &N); // Loop to collect each student's quiz score for (int i = 1; i <= N; i++) { printf("Enter the quiz score for student %d: ", i); scanf("%f", &score); sum += score; // Add the score to the sum } // Calculate the average score if (N > 0) { average = sum / N; // Print the average score printf("The average quiz score is: %.2f\n", average); } else { printf("No students to calculate the average for.\n"); } return 0; }
#include <stdio.h>
int main() {
int N; // Number of students
float sum = 0.0; // Sum of all quiz scores
float score; // Variable to store each student's score
float average; // Variable to store the average score
// Prompt the user to enter the number of students
printf("Enter the number of students: ");
scanf("%d", &N);
// Loop to collect each student's quiz score
for (int i = 1; i <= N; i++) {
printf("Enter the quiz score for student %d: ", i);
scanf("%f", &score);
sum += score; // Add the score to the sum
}
// Calculate the average score
if (N > 0) {
average = sum / N;
// Print the average score
printf("The average quiz score is: %.2f\n", average);
} else {
printf("No students to calculate the average for.\n");
}
return 0;
}