answersLogoWhite

0


Best Answer

#include <stdio.h>

#include <conio.h>

void main(){

int a[10],b[10],c[10],i,j,m,n,tmp,k;

printf("\nEnter the size of the 1st array:");

scanf("%d",&m);

printf("\nEnter the size of the 2nd array:");

scanf("%d",&n);

printf("\nEnter the 1st array values:");

for(i=0;i<m;i++){

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

}

printf("\nEnter the 2nd array values:");

for(i=0;i<n;i++){

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

}

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

{

for(j=0;j<m-i;j++)

{

if(a[j]>a[j+1])

{

tmp=a[j];

a[j]=a[j+1];

a[j+1]=tmp;

}

}

}

printf("\n\n Array in the ascending order is - \n");

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

{

printf("\t %d",a[i]);

}

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

{

for(j=0;j<n-i;j++)

{

if(b[j]>b[j+1])

{

tmp=b[j];

b[j]=b[j+1];

b[j+1]=tmp;

}

}

}

printf("\n\n Array in the ascending order is - \n");

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

{

printf("\t %d",b[i]);

}

i=j=k=0;

while(i<n&&j<m)

{

if(a[i]<b[j])

c[k++]=a[i++];

else

if(a[i]>b[j])

c[k++]=b[j++];

else

{

c[k++]=b[j++];

i++;

j++;

}

}

if(i<n)

{

int t;

for(t=0;t<n;t++)

c[k++]=a[i++];

}

if(j<m)

{

int t;

for(t=0;t<m;t++)

{

c[k++]=b[j++];

}

}

printf("\nFinally sorted join array is:");

for(k=0;k<(m+n);k++)

printf("\t\n %d ",c[k]);

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

write a program to traverse a merge sort

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to merge two array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program to substrate two matrixs in two dimension array?

You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.


How do you merge two array without using function?

Take another array big enough to hold both array copy content of these two array into new one. You merged two array and haven't used a single function.!


Write a c program to find the maximum of two numbers and print out with its position?

maxValue = function (array) {mxm = array[0];for (i=0; i&lt;array.length; i++) {if (array[i]&gt;mxm) {mxm = array[i];}}return mxm;}; i don't know


What is the use of auxiliary array in merge sort?

In merge sort the whole is divided into two sub arrays. (This way of solving problem is called Divide and conquer algorithm) These sub arrays are called auxiliary arrays. First an array A is divided into two auxiliary arrays A1 and A2. Now these auxiliary arrays are further divided until we reach a stage with an auxiliary array of 2 elements. These 2 elements are arranged in incremental order and merged with the previous divided arrays. So we can say that auxiliary array is used to implement the basic principle of merge sort.


How do you write a program in c plus plus to check if an array is symmetric?

To determine if an array is symmetric, the array must be square. If so, check each element against its transpose. If all elements are equal, the array is symmetric.For a two-dimensional array (a matrix) of order n, the following code will determine if it is symmetric or not:templatebool symmetric(const std::array& matrix){for (size_t r=0 ; r

Related questions

How to write aC program to merge two singly linked list?

write a c program to circular queue


Write a program to substrate two matrixs in two dimension array?

You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.


How do you merge two array without using function?

Take another array big enough to hold both array copy content of these two array into new one. You merged two array and haven't used a single function.!


Write a c program to find the maximum of two numbers and print out with its position?

maxValue = function (array) {mxm = array[0];for (i=0; i&lt;array.length; i++) {if (array[i]&gt;mxm) {mxm = array[i];}}return mxm;}; i don't know


How do you write a program of matrix multiplication in a simple way?

you can write by two ways 1 by giving the size of array at declaration 2 by checking condition


What is the use of auxiliary array in merge sort?

In merge sort the whole is divided into two sub arrays. (This way of solving problem is called Divide and conquer algorithm) These sub arrays are called auxiliary arrays. First an array A is divided into two auxiliary arrays A1 and A2. Now these auxiliary arrays are further divided until we reach a stage with an auxiliary array of 2 elements. These 2 elements are arranged in incremental order and merged with the previous divided arrays. So we can say that auxiliary array is used to implement the basic principle of merge sort.


Program to display multiplication of two matrix?

The matrix multiplication in c language : c program is used to multiply matrices with two dimensional array. This program multiplies two matrices which will be entered by the user.


How do you write an array that computes the product of the two numbers in java?

You don't need an array for that. Just do the multiplication, for example: result = factor1 * factor2; Or: result = 5 * 8;


How do you write a program in c plus plus to check if an array is symmetric?

To determine if an array is symmetric, the array must be square. If so, check each element against its transpose. If all elements are equal, the array is symmetric.For a two-dimensional array (a matrix) of order n, the following code will determine if it is symmetric or not:templatebool symmetric(const std::array& matrix){for (size_t r=0 ; r


How do you merge two small businesses?

The way that you can merge two businesses is that the two business owners need to agree on a merge and its price. This must then be taken up with the government. The Government will then agree or disagree on the whole merge. GCSE BUSINESS ANSWER There are two types of merge in business 1. Friendly 2. Hostile


How do you merge 2 Visual C programs to get a single output?

You cannot. A C program can only have one global main function but you'd be trying to compile a program that has two main functions. The only way to merge the two programs is to modularise both programs so that neither is dependent upon their main functions. Once modularised, you can include those modules in any program. Alternatively, you can create binary libraries from the modules and link them into any program.


What is a table array?

A two-dimensional array.