0% found this document useful (0 votes)
28 views2 pages

Merge Two Arrays in C Programming

The document contains a C program that merges two sorted arrays into a single sorted array. It defines a merge function that takes two input arrays and their sizes, and populates a third array with the merged result. The main function handles user input for the arrays and displays the merged output.

Uploaded by

dasaisha419
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Merge Two Arrays in C Programming

The document contains a C program that merges two sorted arrays into a single sorted array. It defines a merge function that takes two input arrays and their sizes, and populates a third array with the merged result. The main function handles user input for the arrays and displays the merged output.

Uploaded by

dasaisha419
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#include<stdio.

h>

void merge(int arr1[], int arr2[], int n1, int n2, int arr3[])

int i = 0, j = 0, k = 0;

while (i< n1 && j < n2)

if (arr1[i] < arr2[j])

arr3[k] = arr1[i];

i++;

else

arr3[k] = arr2[j];

j++;

k++;

while (i < n1)

arr3[k++] = arr1[i++];

while (j < n2)

arr3[k++] = arr2[j++];

int main()

int arr1[10], arr2[10], arr3[30], n1,n2,i;


printf("Enter the number of elements of First Array");

scanf("%d", &n1);

printf("Enter the elements of First Array ");

for(i=0; i< n1; i++)

scanf("%d", &arr1[i]);

printf("Enter the number of elements of Second Array ");

scanf("%d", &n2);

printf("Enter of elements of Second Array ");

for(i=0; i< n2; i++)

scanf("%d", &arr2[i]);

merge(arr1, arr2, n1, n2, arr3);

printf("Array after merging\n");

for (i=0; i < n1+n2; i++)

printf("%d ", arr3[i]);

return 0;

You might also like