Write a c program to merge two array in single array
BM Balmiki Mandal 06 Sep 2022 10 views 0 comments C Programming

Write a c program to merge two array in single array

C Program to merge two arrays in a single array in c

Merging two arrays into a single array involves taking all the elements from both arrays and creating a new array that contains all the elements in a single sequence. 

To merge two arrays into a single array in C, we can use the following steps:

  1. Declare a third array to store the merged array. The size of the third array should be equal to the sum of the sizes of the two original arrays.
  2. Copy the elements of the first original array to the merged array.
  3. Copy the elements of the second original array to the merged array.

C program shows how to merge two arrays into a single array:

#include
int main()
{
    int a[5]={10,20,30,40,50};
    int b[5]={60,70,80,90,100};
    int c[10],i;
    printf("Murged array is\n");
    for(i=0;i<5;i++)
    {
        c[i]=a[i];
        c[i+5]=b[i];
    }
    for(i=0;i<10;i++)
    printf(" %d",c[i]);
    printf("\n");
}

Output:

The merged array is: 1 2 3 4 5 6 7 8 9 10

Top Resources

Write a program to merge two strings alternatively in c

Write a c program to merge two arrays in single array 

write a program to merge two string in a single single string.

Further Reading:

 For further information and examples, Please visit[ C-Programming From Scratch to Advanced 2023-2024]

 

Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026