60 507
Assignments Done
Successfully Done
In April 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
Expert's answer
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;
cout<<"Enter array: "<<endl;
int *a = new int[n];
for(int i = 0; i<n; i++)
cout<<"Enter the size of B array"<<endl;
cout<<"Enter array: "<<endl;
int *b = new int[m];
for(int i = 0; i<m; 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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions