Calculate average marks for each student Dry Run in C

Calculate average marks for each student 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.

Calculate average marks for each student Program Code

#include <stdio.h>

#define SUBJECTS 5

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

int main() {
    struct Student students[30];
    int n, i, j;
    
    printf("Enter number of students: ");
    scanf("%d", &n);
    
    for(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);
        
        int sum = 0;
        for(j = 0; j < SUBJECTS; j++) {
            printf("Subject %d marks: ", j+1);
            scanf("%d", &students[i].marks[j]);
            sum += students[i].marks[j];
        }
        students[i].average = (float)sum / SUBJECTS;
    }
    
    printf("\n%-6s %-20s %-10s\n", "Roll", "Name", "Average");
    for(i = 0; i < n; i++) {
        printf("%-6d %-20s %-10.2f\n", 
               students[i].roll, students[i].name, students[i].average);
    }
    
    return 0;
}

View the complete Structures Arrays programs page.

Program Console Calculate average marks for each student Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.