Find largest digit in a number (Recursion) Dry Run in C

Find largest digit in a number (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.

Find largest digit in a number (Recursion) Program Code

#include <stdio.h>

int largestDigit(int n) {
    // BASE CASE: single digit, return itself
    if(n < 10) {
        return n;
    }
    int lastDigit = n % 10;
    int maxInRest = largestDigit(n / 10);
    // Return the larger of lastDigit and max from remaining
    return (lastDigit > maxInRest) ? lastDigit : maxInRest;
}

int main() {
    int num = 739582;
    int result = largestDigit(num);
    printf("Number: %d\n", num);
    printf("Largest digit = %d\n", result);
    return 0;
}

View the complete Recursion programs page.

Program Console Find largest digit in a number (Recursion) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.