Get Off-Campus Placement Jobs Info !!!
Programs asked in Mettl Coding Round
Click To Practce List of Programs asked in Nagarro !!!

Program Discussion :: Array

Home > Programs > Array

76 / 23

Write a program to merge two sorted array.

Answer:

#include  
#include 
using namespace std;
void main()
{
    int array1[50], array2[50], array3[100], m, n, i, j, k = 0;
    coutm;
    coutarray1[i];
    }
    coutn;
    coutarray2[i];
    }
    i = 0;
    j = 0;
    while (i < m && j < n)
    {
        if (array1[i] < array2[j])
        {
            array3[k] = array1[i];
            i++;
        }
        else
        {
            array3[k] = array2[j];
            j++;
        }
        k++;
    }
    if (i >= m)
    {
        while (j < n)
        {
            array3[k] = array2[j];
            j++;
            k++;
        }
    }
    if (j >= n)
    {
        while (i < m)
        {
            array3[k] = array1[i];
            i++;
            k++;
        }
    }
    cout

Asked In :: Juniper Network

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here:



Language:

Post Your Reply Here: