Write a program in C++ that permits to: a. Define an array A[n] of real numbers
ID: 3583367 • Letter: W
Question
Write a program in C++ that permits to: a. Define an array A[n] of real numbers (n constant). b. Define an array B[m] of real numbers (m constant). c. Fill in the two vectors with random numbers between 50 and 50+m+n. d. Sort the two arrays in ascending order. e. Combine the elements of the two sorted arrays A and B in a third array C sorted in ascending order. Display the result. Write a program in C++ that permits to: a. Define an array A[n] of real numbers (n constant). b. Define an array B[m] of real numbers (m constant). c. Fill in the two vectors with random numbers between 50 and 50+m+n. d. Sort the two arrays in ascending order. e. Combine the elements of the two sorted arrays A and B in a third array C sorted in ascending order. Display the result. a. Define an array A[n] of real numbers (n constant). b. Define an array B[m] of real numbers (m constant). c. Fill in the two vectors with random numbers between 50 and 50+m+n. d. Sort the two arrays in ascending order. e. Combine the elements of the two sorted arrays A and B in a third array C sorted in ascending order. Display the result.Explanation / Answer
1
int i = 100;
double[] A = new double[i];
for (int n = 0; n< A.Length; n++)
A[n] = n+ 1;
2
int i = 100;
double[] B = new double[i];
for (int n = 0; n< B.Length; n++)
B[n] = n+ 1;
3
Fill in the two vectors with random numbers between 50 and 50+m+n.
4
#include<iostream.h>
#include<conio.h>
void main()
{
int ii,s[10],temporary,jj;
clrscr();
cout<<"Enter any 100 num in array: ";
for(ii=0;ii<=10;ii++)
{
cin>>s[ii];
}
cout<<" display Data before sorting: ";
for(jj=0;jj<10;jj++)
{
cout<<s[jj];
}
for(ii=0;ii<=10;ii++)
{
for(jj=0;jj<=10-ii;jj++)
{
if(s[jj]>s[jj+1])
{
temporary=s[jj];
s[jj]=s[jj+1];
s[jj+1]=temporary;
}
}
}
cout<<" display Data after sorting: ";
for(jj=0;jj<10;jj++)
{
cout<<s[jj];
}
getch();
}
5
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[50], B[50], size1, size2, size, i, j, k, c[100];
cout<<"Enter A Size : ";
cin>>size1;
cout<<"Enter A Elements : ";
for(i=0; i<Asize1; i++)
{
cin>>A[i];
}
cout<<"Enter B Size : ";
cin>>size2;
cout<<"Enter B Elements : ";
for(i=0; i<size2; i++)
{
cin>>B[i];
}
for(i=0; i<size1; i++)
{
c[i]=A[i];
}
size=size1+size2;
for(i=0, k=size1; k<size && i<size2; i++, k++)
{
c[k]=B[i];
}
cout<<"Now the new array after merging is : ";
for(i=0; i<size; i++)
{
cout<<c[i]<<" ";
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.