Merge Two Arrays

Medium Arrays
Solve in Playground →

Problem Statement

Write a C program to merge two arrays into a third array and print the merged array.

Input Format

First line contains n1. Second line contains n1 elements. Third line contains n2. Fourth line contains n2 elements.

Output Format

Print the merged array of size n1 + n2 separated by spaces.

Constraints

1 <= n1, n2 <= 50

Sample Input

3
1 2 3
2
4 5

Sample Output

1 2 3 4 5

Explanation

Copy all elements of the first array into the result array, then append all elements of the second array.

Starter Code

#include <stdio.h>

int main() {
    int n1, n2;
    if (scanf("%d", &n1) == 1) {
        int arr1[50];
        for (int i = 0; i < n1; i++) {
            scanf("%d", &arr1[i]);
        }
        scanf("%d", &n2);
        int arr2[50];
        for (int i = 0; i < n2; i++) {
            scanf("%d", &arr2[i]);
        }
        // Write your code here to merge and print
    }
    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