63 155
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #53767 in C++ for ysrao

Question #53767
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.
Expert's answer
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;
}

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!

Comments

Assignment Expert
10.01.18, 15:49

Yes

Rohit
10.01.18, 09:04

Is this complete answer??

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions