Menu-Driven Program (Calculator) Dry Run in C

Menu-Driven Program (Calculator) is an interactive C dry run visualizer from the Switch 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.

Menu-Driven Program (Calculator) Program Code

#include <stdio.h>
int main() {
    int a, b, choice;
    
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    
    printf("\n1. Addition");
    printf("\n2. Subtraction");
    printf("\n3. Multiplication");
    printf("\n4. Division");
    printf("\nEnter your choice: ");
    scanf("%d", &choice);
    
    switch(choice) {
        case 1:
            printf("Result: %d\n", a + b);
            break;
        case 2:
            printf("Result: %d\n", a - b);
            break;
        case 3:
            printf("Result: %d\n", a * b);
            break;
        case 4:
            if(b != 0)
                printf("Result: %d\n", a / b);
            else
                printf("Division by zero error\n");
            break;
        default:
            printf("Invalid choice\n");
            break;
    }
    return 0;
}

View the complete Switch programs page.

Program Console Menu-Driven Program (Calculator) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.