POP Lab Manual

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.
Key Concepts:
Structure Definition: struct Student { char name[50]; float marks; }
Array of Structures: struct Student s[n]
Average Calculation: sum = Σ(marks) / n
Performance Analysis: Compare individual marks with class average

Algorithm

  1. Define Structure: Create Student structure with name and marks fields
  2. Input Number of Students: Read N (number of students) from user
  3. Create Array: Declare array of N Student structures
  4. Read Student Data: Loop through array and input name and marks for each student
  5. Calculate Sum: Add all student marks while reading input
  6. Compute Average: Divide total sum by number of students
  7. Display Average: Print the calculated class average
  8. List Above Average: Loop through students and display those with marks > average
  9. 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;
}

Output


// Sample Output 1 - Basic Class Analysis
Enter number of students: 5
Enter name of student 1: Alice
Enter marks of Alice: 85.5
Enter name of student 2: Bob
Enter marks of Bob: 72.0
Enter name of student 3: Carol
Enter marks of Carol: 94.5
Enter name of student 4: David
Enter marks of David: 68.5
Enter name of student 5: Emma
Enter marks of Emma: 89.0

Class Average Marks = 81.90

Students scoring above average:
Alice (85.50)
Carol (94.50)
Emma (89.00)

Students scoring below average:
Bob (72.00)
David (68.50)

// Sample Output 2 - All Students Above Average
Enter number of students: 3
Enter name of student 1: John
Enter marks of John: 95.0
Enter name of student 2: Jane
Enter marks of Jane: 92.5
Enter name of student 3: Jack
Enter marks of Jack: 88.0

Class Average Marks = 91.83

Students scoring above average:
John (95.00)
Jane (92.50)

Students scoring below average:
Jack (88.00)

// Sample Output 3 - Mixed Performance Class
Enter number of students: 4
Enter name of student 1: Alex
Enter marks of Alex: 45.0
Enter name of student 2: Sarah
Enter marks of Sarah: 78.5
Enter name of student 3: Mike
Enter marks of Mike: 92.0
Enter name of student 4: Lisa
Enter marks of Lisa: 67.5

Class Average Marks = 70.75

Students scoring above average:
Sarah (78.50)
Mike (92.00)

Students scoring below average:
Alex (45.00)
Lisa (67.50)

// Sample Output 4 - Single Student
Enter number of students: 1
Enter name of student 1: Student
Enter marks of Student: 75.0

Class Average Marks = 75.00

Students scoring above average:

Students scoring below average: