Write a program that merges 2 arrays. The user need to get 2 arrays , one of the
ID: 3636385 • Letter: W
Question
Write a program that merges 2 arrays. The user need to get 2 arrays , one of them is array A of size 5 and it is initialized randomly in the range (1-20). And the other one is array B of size 5 and the user will enter its values. Merging the two arrays will be in a new array C of size 10.
Note: Merging the arrays should be done in a separate function.
Simple output:
** This program merges 2 arrays:
** First array a is randomly initialized: 2 3 1 5 19
** Please enter the values of array b:
1 2 5 100 1
** then C is 2 3 1 5 19 1 2 5 100 1
Explanation / Answer
#include<iostream.h>
#include<iostream.h>
int main()
{
char array1[5];
char array2[5];
char array3[10];
int i=0;
for(i=0; i<5; i++)
{
array1[i] = Math.random()*20;
}
cout<<"Enter value in second array";
for(i=0; i<5; i++)
{
cin>>array2[i];
}
for(i=0; i<10; i++);
{
for(int k=0; k<10; k++)
{
if(array1[k]==array2[k])
{
array3[i]=array1[k];
i++;
//continue;
}
else
{
array3[++i]=array2[k];
array3[++i];
for(i=0; i<20; i++);
{
cout<<array3[i];
}
}
system("pause");
}
}
}
Sample Output
Enter values in first array: a h b c u v
Enter values in Second array: y u d f g
Merged array: y h u b d c f g
Sorted Array in ascending order: b c d e f g h u y
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.