Our website use cookies, which help us to improve our site and enables us to deliver the best possible service and customer experience. By clicking accept you are agreeing to our cookies policy. Find out more
If you notice any factual inaccuracies or other issues with this profile, please let us know. Please do not include any personal health information in this form.
Like Answer
#include <stdio.h>#include <stdlib.h>
// Define the structure for a studentstruct Student { char name[50]; int marks;};
// Function to compute the average marksfloat computeAverage(struct Student students[], int numStudents) { int totalMarks = 0;
for (int i = 0; i < numStudents; i++) { totalMarks += students[i].marks; }
return (float)totalMarks / numStudents;}
// Function to display students above and below the average marksvoid displayAboveBelowAverage(struct Student students[], int numStudents, float average) { printf("\nStudents scoring above average:\n"); for (int i = 0; i < numStudents; i++) { if (students[i].marks > average) { printf("%s: %d\n", students[i].name, students[i].marks); } }
printf("\nStudents scoring below or equal to average:\n"); for (int i = 0; i < numStudents; i++) { if (students[i].marks <= average) { printf("%s: %d\n", students[i].name, students[i].marks); } }}
int main() { int numStudents;
printf("Enter the number of students: "); scanf("%d", &numStudents);
// Dynamically allocate memory for an array of students struct Student *students = (struct Student*)malloc(numStudents * sizeof(struct Student));
for (int i = 0; i < numStudents; i++) { printf("\nEnter details for student %d:\n", i + 1); printf("Name: "); scanf("%s", students[i].name); printf("Marks: "); scanf("%d", &students[i].marks); }
float average = computeAverage(students, numStudents);
printf("\nAverage marks: %.2f\n", average);
displayAboveBelowAverage(students, numStudents, average);
free(students);
return 0;}