Geometric Progression (nth term) - Recursion Dry Run in C

Geometric Progression (nth term) - Recursion is an interactive C dry run visualizer from the Recursion 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.

Geometric Progression (nth term) - Recursion Program Code

#include <stdio.h>

// GP: a, ar, ar?, ar?, ...
// nth term = a * r^(n-1)
int gpTerm(int a, int r, int n) {
    if(n == 1) {
        return a;
    }

    int previousTerm = gpTerm(a, r, n - 1);
    int currentTerm = r * previousTerm;
    return currentTerm;
}

int main() {
    int firstTerm = 3;
    int ratio = 2;
    int position = 5;
    
    int term = gpTerm(firstTerm, ratio, position);
    printf("GP: a=%d, r=%d\n", firstTerm, ratio);
    printf("%dth term = %d\n", position, term);
    return 0;
}

View the complete Recursion programs page.

Program Console Geometric Progression (nth term) - Recursion Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.