Calculate total and average of student marks Dry Run in C

Calculate total and average of student marks is an interactive C dry run visualizer from the Structures 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 total and average of student marks Program Code

#include <stdio.h>

struct Student {
    int roll;
    char name[30];
    int marks[5];  // Array of 5 subject marks
};

int main() {
    struct Student s = {101, "Priya", {85, 90, 78, 92, 88}};
    int total = 0;
    int i;
    
    // Calculate total marks
    for(i = 0; i < 5; i++) {
        total += s.marks[i];
    }
    
    float average = total / 5.0;
    
    printf("Student: %s (Roll: %d)\n", s.name, s.roll);
    printf("Marks: ");
    for(i = 0; i < 5; i++) {
        printf("%d ", s.marks[i]);
    }
    printf("\nTotal: %d\n", total);
    printf("Average: %.2f\n", average);
    
    return 0;
}

View the complete Structures programs page.

Program Console Calculate total and average of student marks Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.