Count students above average Dry Run in C

Count students above average is an interactive C dry run visualizer from the Structures Arrays programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.

This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.

Count students above average Program Code

#include <stdio.h>

struct Student {
    int roll;
    char name[40];
    float marks;
};

float calculateAverage(struct Student s[], int n) {
    float sum = 0;
    for(int i = 0; i < n; i++) {
        sum += s[i].marks;
    }
    return sum / n;
}

int countAboveAverage(struct Student s[], int n, float avg) {
    int count = 0;
    for(int i = 0; i < n; i++) {
        if(s[i].marks > avg) {
            count++;
        }
    }
    return count;
}

int main() {
    struct Student students[50];
    int n;
    
    printf("Enter number of students: ");
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++) {
        printf("\nStudent %d:\n", i+1);
        printf("Roll: "); scanf("%d", &students[i].roll);
        printf("Name: "); scanf(" %[^\n]", students[i].name);
        printf("Marks: "); scanf("%f", &students[i].marks);
    }
    
    float classAvg = calculateAverage(students, n);
    int aboveAvgCount = countAboveAverage(students, n, classAvg);
    
    printf("\n========== STATISTICS ==========\n");
    printf("Class Average: %.2f\n", classAvg);
    printf("Students above average: %d\n", aboveAvgCount);
    printf("\nStudents above average:\n");
    
    for(int i = 0; i < n; i++) {
        if(students[i].marks > classAvg) {
            printf("- %s (Roll: %d, Marks: %.2f)\n", 
                   students[i].name, students[i].roll, students[i].marks);
        }
    }
    
    return 0;
}

View the complete Structures Arrays programs page.

Program Console Count students above average Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.