C/C++ Program for Union of Two Arrays

Here you will get C/C++ program to find union of two arrays.

For example:

First array: {1, 3, 7, 9}

Second array: {1, 4, 6}

Union: {1, 3, 4, 7, 6, 9}

 

C/C++ Program for Union of Two Arrays

Union of Two Sorted Arrays

If two arrays are sorted then their union can be found in following way.

C Program

 

Output

Enter size of first array:4
Enter elements of first array in ascending order:
1 2 3 5

Enter size of second array:5
Enter elements of second array in ascending order:
1 3 5 7 9

Union of two arrays is:
1 2 3 5 7 9

 

C++ Program

 

Union of Two Unsorted Arrays

If two arrays are unsorted then their union can be found in following way.

C Program

 

Output

Enter size of first array:3
Enter elements of first array:
1 3 5

Enter size of second array:4
Enter elements of second array:
1 2 3 6

Union of two arrays is:
1 3 5 2 6

 

C++ Program

4 thoughts on “C/C++ Program for Union of Two Arrays”

  1. I’m sorry sir but sometimes can you puta comment on your program, it really helps if you put some code thanks. And followed you and added (y)

  2. sir what if the array elemnts have more than 1 elemnts repeating
    like if array 1 has 1,2,3,3,4,4,4,5 and array 2 has 7,8,9,9,9
    will this code work ????

Leave a Comment

Your email address will not be published. Required fields are marked *