"How will you merge these two arrays? Write the program
Array: A 1 18 22 43
Array: B 3 4 6 20 34 46 55
Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

Answer Posted / sandeep

#include<stdio.h>
#include<conio.h">

#define max 10

void main()
{
int a[max],b[max],c[2*max],i,j,k,n,m;
clrscr();
printf("size of array a:");
scanf("%d",&n);

printf("enter a elements: \n");
for(i=0;i<n;i++)

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


printf("size of array b:");
scanf("%d",&m);

printf("enter a elements: \n");
for(i=0;i<m;i++)

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




for(i=0,j=0,k=0; i<n && j<m; k++)

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

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

else

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

while(i<n)

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


while(j<m)

c[k++] = b[j++];
for(i=0;i<m+n-1;i++) //place each element in to correct position
{
for(j=i+1;j<m+n;j++)
{
if(c[i]>c[j]) //swapping
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}


printf("\n array c:\n");
for(i=0;i<(m+n); i++)
printf("%d", c[i]);
getch();

}

Is This Answer Correct ?    10 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Name the implicit member functions of a class.

596


Differentiate between declaration and definition.

587


Where can I run c++ program?

603


What is ifstream c++?

560


What is the best it certification?

584






Which bit wise operator is suitable for putting on a particular bit in a number?

721


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

642


Write about the local class and mention its use?

611


How to declare a function pointer?

576


Eplain extern keyword?

563


What is meant by entry controlled loop? What all C++ loops are exit controlled?

567


When do we run a shell in the unix system? How will you tell which shell you are running?

556


Draw a flow chart and write a program for the difference between the sum of elements with odd and even numbers. Two dimensional array.

5899


What are the differences between malloc() and calloc()?

613


Do you know what are the new features that iso/ansi c++ has added to original c++ specifications?

558