Consider A, B, C as three arrays of size m,n and m + n respectively. Array A is stored in ascending order whereas array B is stored in descending order. Write a C++ program to produce a third array C, containing all the data of arrays A and B and arranged in descending order. Display the data of array C only.
1
Expert's answer
2015-07-30T02:23:20-0400
Solve #include <iostream>
using namespace std;
int main() { int n=4; int m=5; int a[]={1,3,5,7}; int b[]={8,6,4,2,0}; int *c; c=new int[n+m]; int i_a=n-1, i_b=0; int i=0; while((i_a>=0)&&(i_b<m)) { if(a[i_a]<b[i_b]) { c[i]=b[i_b]; i++; i_b++; } else { c[i]=a[i_a]; i++; i_a--; } } while(i_a>=0) { c[i]=a[i_a]; i++; i_a--; } while(i_b<m) { c[i]=b[i_b]; i++; i_b++; } for(i=0;i<n+m;i++) cout<<c[i]<<" "; return 0; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Yes
Is this complete answer??
Leave a comment