Compute exponential series: 1 + x + x²/2! + ... up to n terms Dry Run in C

Compute exponential series: 1 + x + x²/2! + ... up to n terms is an interactive C dry run visualizer from the For 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.

Compute exponential series: 1 + x + x²/2! + ... up to n terms Program Code

#include <stdio.h>
int main() {
    int x, n, i;
    float sum = 1.0, term = 1.0, fact = 1.0, power = 1.0;
    printf("Enter x and number of terms: ");
    scanf("%d %d", &x, &n);
    
    for(i = 1; i < n; i++) {
        power = power * x;      // x^i
        fact = fact * i;         // i!
        term = power / fact;     // x^i / i!
        sum = sum + term;        // add to sum
    }
    
    printf("e^%d ≈ %.6f\n", x, sum);
    return 0;
}

View the complete For programs page.

Program Console Compute exponential series: 1 + x + x²/2! + ... up to n terms Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.