Program 10
Implement
structures to read, write and compute
average marks of the students, list the students scoring
above and below the average marks for a class of N students.
This program demonstrates the use of structures, arrays of structures, and statistical analysis
of student data for academic performance evaluation.
Algorithm
- Define Structure: Create Student structure with name and marks fields
- Input Number of Students: Read N (number of students) from user
- Create Array: Declare array of N Student structures
- Read Student Data: Loop through array and input name and marks for each student
- Calculate Sum: Add all student marks while reading input
- Compute Average: Divide total sum by number of students
- Display Average: Print the calculated class average
- List Above Average: Loop through students and display those with marks > average
- List Below Average: Loop through students and display those with marks < average
Flowchart
START
→
Input N
→
Read Student Data
→
Calculate Sum
→
Compute Average
→
Display Results
→
List Performance
→
STOP
Code
#include <stdio.h>
struct Student {
char name[50];
float marks;
};
int main() {
int n, i;
float sum = 0, avg;
printf("Enter number of students: ");
scanf("%d", &n);
struct Student s[n];
// Input student details
for (i = 0; i < n; i++) {
printf("Enter name of student %d: ", i + 1);
scanf("%s", s[i].name);
printf("Enter marks of %s: ", s[i].name);
scanf("%f", &s[i].marks);
sum += s[i].marks;
}
// Calculate average
avg = sum / n;
printf("\nClass Average Marks = %.2f\n", avg);
// Display students scoring above average
printf("\nStudents scoring above average:\n");
for (i = 0; i < n; i++) {
if (s[i].marks > avg)
printf("%s (%.2f)\n", s[i].name, s[i].marks);
}
// Display students scoring below average
printf("\nStudents scoring below average:\n");
for (i = 0; i < n; i++) {
if (s[i].marks < avg)
printf("%s (%.2f)\n", s[i].name, s[i].marks);
}
return 0;
}