R23 Print all sequences using 1 and 2 to reach N Dry Run in C

R23 Print all sequences using 1 and 2 to reach N 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.

R23 Print all sequences using 1 and 2 to reach N Program Code

#include <stdio.h>

void printSequences(int remaining, char seq[], int pos) {
    if(remaining == 0) {
        seq[pos] = '\0';
        printf("%s\n", seq);
        return;
    }
    if(remaining >= 1) {
        seq[pos] = '1';
        printSequences(remaining - 1, seq, pos + 1);
    }
    if(remaining >= 2) {
        seq[pos] = '2';
        printSequences(remaining - 2, seq, pos + 1);
    }
}

int main() {
    int n = 4;
    char buffer[10];
    printf("Ways to reach %d using 1 and 2:\n", n);
    printSequences(n, buffer, 0);
    return 0;
}

View the complete Recursion programs page.

Program Console R23 Print all sequences using 1 and 2 to reach N Topic: C Vignaankosh.com
Execution Panel
Step 0/0
Console is empty.