"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
Why do we need runtime polymorphism in c++?
Do you know about C++ 11 standard?
What are the 2 main types of data structures?
What are the five basic elements of a c++ program?
What is c++ best used for?
How static variables and local variablesare similar and dissimilar?
Is there any difference between int [] a and int a [] in c++?
What is the difference between while and do while loop?
Difference between class and structure.
Write a program to concatenate two strings.
Is c++ map a hash table?
How do you add an element to a set in c++?
What is ctime c++?
what is scupper?
Is c++ the best programming language?