"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 / manish podiyal
#include<iostream.h>
class array
{
int a[15],b[15],c[15];
public:
void setdata()
{
a[10]={1,18,22,43,NULL};
b[10]={3,4,6,20,34,46,55,NULL};
}
void output()
{
while(a[i]!=NULL)
{
for(i=0;i<15;i++)
{
if(a[i]< b[i])
{
c[i]=a[i];
i++;
}
else if(a[i] > b[i])
{
c[i]=b[i];
i++;
}
}
}
if(a[i]==NULL)
{
c[i]=b[i];
i++;
}
}
};
void main()
{
array o;
o.setdata();
o.output();
}
Is This Answer Correct ? | 28 Yes | 26 No |
Post New Answer View All Answers
What is an adaptor class or wrapper class in c++?
Can we sort map in c++?
How should a contructor handle a failure?
What is bubble sort c++?
Write about the access privileges in c++ and also mention about its default access level?
What is guard code in c++?
Should the member functions which are made public in the base class be hidden?
What is the default access level?
What is the array and initializing arrays in c++?
Explain differences between new() and delete()?
Write about the local class and mention its use?
Do the names of parameters have to agree in the prototype, definition, and call to the function?
What is difference between array and vector in c++?
Is java easier than c++?
How should runtime errors be handled in c++?