Computer Science, asked by jaganathmenon99, 1 year ago

Consider A, B, C as three arrays of size m,n and m + n respectively. Array A is stored in ascending orderwhereas array B is stored in descending order. Write a C++ program to produce a trd array C, containingall the data of arrays A and B and arranged in descending order. Display the data of array C only.

Answers

Answered by Neeraj723
9
Hii dear here is your answer

#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;
]
Similar questions