C C++ program to merge two arrays

C C++ program to merge two arrays

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

C Language में character set क्या होता है जानने के लिए देखें—Character set of C

C Language में Character Set क्या होता है जानने के लिए देखें—Tokens in C

C program to merge two arrays

#include<stdio.h>
int main()
{
    int a1[5],a2[5],a3[10],i=0,j=0;
    printf("Enter elements of Array1:\n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a1[i]);
    }
    printf("Enter elements of Array1:\n");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a2[i]);
    }
    for(i=0;i<10;i++)
    {
        if(i<5)
        {
         a3[i]=a1[i];
        }
        else
        {
            a3[i]=a2[j];
            j++;
        }
    }
    printf("Merged Array:\n");
    for(i=0;i<10;i++)
    {
        printf("%d ",a3[i]);
    }
    return 0;
}

C++ program to merge two arrays

#include<iostream>
using namespace std;
int main()
{
    int a1[5],a2[5],a3[10],i=0,j=0;
    cout<<"Enter elements of Array1:\n";
    for(i=0;i<5;i++)
    {
        cin>>a1[i];
    }
    cout<<"Enter elements of Array1:\n";
    for(i=0;i<5;i++)
    {
        cin>>a2[i];
    }
    for(i=0;i<10;i++)
    {
        if(i<5)
        {
         a3[i]=a1[i];
        }
        else
        {
            a3[i]=a2[j];
            j++;
        }
    }
    cout<<"Merged Array:\n";
    for(i=0;i<10;i++)
    {
        cout<<a3[i]<<" ";
    }
    return 0;
}

Output of C C++ program to merge two arrays

C C++ program to merge two arrays

Similar array programs in C C++

  1. Declaration and initialization of array
  2. Input-output in array
  3. Sum and average of array elements
  4. Largest Element in Array
  5. Smallest element in Array
  6. Reverse Elements of Array
  7. Searching in array (Linear search)
  8. Sorting in array (Selection sort)
  9. Pointer to array
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer