Calculate result (marks) using function Dry Run in C

Calculate result (marks) using function is an interactive C dry run visualizer from the Struct Functions Pointers 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 result (marks) using function Program Code

#include <stdio.h>

struct Student {
    int roll;
    char name[50];
    int marks[5];
    float total;
    float percentage;
    char grade;
};

void calculateResult(struct Student *s) {
    s->total = 0;
    
    for(int i = 0; i < 5; i++) {
        s->total += s->marks[i];
    }
    
    s->percentage = s->total / 5;
    
    if(s->percentage >= 90)
        s->grade = 'A';
    else if(s->percentage >= 75)
        s->grade = 'B';
    else if(s->percentage >= 60)
        s->grade = 'C';
    else if(s->percentage >= 45)
        s->grade = 'D';
    else
        s->grade = 'F';
}

int main() {
    struct Student student = {101, "Emma Watson", {85, 90, 78, 92, 88}, 0, 0, ' '};
    
    calculateResult(&student);
    
    printf("Student Result:\n");
    printf("Roll: %d\n", student.roll);
    printf("Name: %s\n", student.name);
    printf("Total Marks: %.0f/500\n", student.total);
    printf("Percentage: %.2f%%\n", student.percentage);
    printf("Grade: %c\n", student.grade);
    return 0;
}

View the complete Struct Functions Pointers programs page.

Program Console Calculate result (marks) using function Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.