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
1
Expert's answer
2017-12-29T02:37:44-0500
#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]; }
Comments
Leave a comment