Generate Binary Numbers

Medium Queue: Applications PRO
🔒 Login to Unlock

Problem Statement

Write a C program using a queue to generate and print binary numbers from 1 to n.

Input Format

An integer n.

Output Format

Print binary numbers from 1 to n separated by spaces.

Constraints

1 <= n <= 20

Sample Input

5

Sample Output

1 10 11 100 101

Explanation

Enqueue "1", then iteratively dequeue, print, and enqueue strings formed by appending "0" and "1".

Starter Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int n;
    if (scanf("%d", &n) == 1) {
        // Write your code here to generate binary numbers using queue
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used