# Answer to Question #54109 in C++ for Guruwinder

Question #54109

Consider A,B,C as three arrays of size m,n and m+n respectively. Array A is stored in ascending order where as 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

#include <iostream>

using namespace std;

void BubbleSort(int* arr, int size);

int main() {

const int n = 7;

const int m = 6;

int A[] = {45, 47, 55, 78, 81, 90, 102};

int B[] = {134, 122, 116, 90, 71, 34};

int* C = new int [n+m];

for (int i = 0; i < n+m; i++) {

if (i >= n)

C[i] = B[i - n];

else

C[i] = A[i];

}

BubbleSort(C, n+m);

cout<<"C : ";

for (int i = 0; i < n+m; i++)

cout<<C[i]<<" ";

cout<<endl;

cin.get();

return 0;

}

void BubbleSort(int* arr, int size)

{

int tmp;

for(int i = 0; i < size - 1; ++i)

{

for(int j = 0;j < size - 1; ++j)

{

if (arr[j + 1] > arr[j])

{

tmp = arr[j + 1];

arr[j + 1] = arr[j];

arr[j] = tmp;

}

}

}

}

using namespace std;

void BubbleSort(int* arr, int size);

int main() {

const int n = 7;

const int m = 6;

int A[] = {45, 47, 55, 78, 81, 90, 102};

int B[] = {134, 122, 116, 90, 71, 34};

int* C = new int [n+m];

for (int i = 0; i < n+m; i++) {

if (i >= n)

C[i] = B[i - n];

else

C[i] = A[i];

}

BubbleSort(C, n+m);

cout<<"C : ";

for (int i = 0; i < n+m; i++)

cout<<C[i]<<" ";

cout<<endl;

cin.get();

return 0;

}

void BubbleSort(int* arr, int size)

{

int tmp;

for(int i = 0; i < size - 1; ++i)

{

for(int j = 0;j < size - 1; ++j)

{

if (arr[j + 1] > arr[j])

{

tmp = arr[j + 1];

arr[j + 1] = arr[j];

arr[j] = tmp;

}

}

}

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment