R29 Mutual recursion (Two functions calling each other) Dry Run in C

R29 Mutual recursion (Two functions calling each other) 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.

R29 Mutual recursion (Two functions calling each other) Program Code

#include <stdio.h>

// Forward declarations (required for mutual recursion)
int isEven(int n);
int isOdd(int n);

int isEven(int n) {
    if(n == 0) {
        return 1;  // 0 is even
    }
    int result = isOdd(n - 1);   // Even(n) = Odd(n-1)
    return result;
}

int isOdd(int n) {
    if(n == 0) {
        return 0;   // 0 is not odd
    }
    int result = isEven(n - 1);  // Odd(n) = Even(n-1)
    return result;
}

int main() {
    int num = 7;
    printf("%d is %s\n", num, isEven(num) ? "Even" : "Odd");
    num = 8;
    printf("%d is %s\n", num, isEven(num) ? "Even" : "Odd");
    num = 0;
    printf("%d is %s\n", num, isEven(num) ? "Even" : "Odd");
    return 0;
}

View the complete Recursion programs page.

Program Console R29 Mutual recursion (Two functions calling each other) Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.