Check if a number contains a specific digit (Recursion) Dry Run in C

Check if a number contains a specific digit (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.

Check if a number contains a specific digit (Recursion) Program Code

#include <stdio.h>
#include <stdbool.h>

bool containsDigit(int n, int target) {
    if(n == 0) {
        return false;  // No digits left to check
    }
    if(n % 10 == target) {
        return true;   // Found the digit
    }
    return containsDigit(n / 10, target);
}

int main() {
    int num = 48236;
    int search = 8;
    
    if(containsDigit(num, search))
        printf("%d contains digit %d\n", num, search);
    else
        printf("%d does NOT contain digit %d\n", num, search);
    return 0;
}

View the complete Recursion programs page.

Program Console Check if a number contains a specific digit (Recursion) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.