67 257
Assignments Done
99,3%
Successfully Done
In November 2018

# Answer to Question #72152 in C++ for Amar

Question #72152
Consider A,B,C as three arrays of size m,n and m+n respectively.Array A is stored in ascending orders where as array B is stored in descending order.Write a C++ program to produce a third array C, containing all the data of array A and B and arranged in descending order.Display the data of array C only
#include<iostream>
#include<cstdlib>
using namespace std;
int compare( const void *x1, const void *x2)
{
return(*(int*)x1 - *(int*)x2);
}
int main()
{
int n, m;
cout<<"Enter the size of A array"<<endl;
cin>>n;
cout<<"Enter array: "<<endl;
int *a = new int[n];
for(int i = 0; i<n; i++)
{
cin>>a[i];
}
cout<<"Enter the size of B array"<<endl;
cin>>m;
cout<<"Enter array: "<<endl;
int *b = new int[m];
for(int i = 0; i<m; i++)
{
cin>>b[i];
}
int k = 0;
int*c = new int[n+m];
for(int i = 0; i<n; i++)
{
c[k++] = a[i];
}
for(int i = 0; i<m; i++)
{
c[k++] = b[i];
}

qsort(c,n+m,sizeof(int), compare);
cout<<"The resulting array: "<<endl;
for(int i = 0; i<n+m; i++)
cout<<c[i]<<" ";
delete[] c;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!