Answer to Question #277316 in C++ for nyycjj

Question #277316

Write a program that reads 5 integers into an array and:



a. Multiplied it by 2 and store into another array of the same size.



b. Merge the two arrays into third array




1
Expert's answer
2021-12-08T08:15:52-0500
#include <iostream>
using namespace std;








int main() {
	//reads 5 integers into an array
	int numbers[5];
	int numbersMultipliedBy2[5];
	int mergeNumbers[10];
	for(int i=0;i<5;i++){
		cout<<"Enter the number "<<(i+1)<<": ";
		cin>>numbers[i];
	}
	//a. Multiplied it by 2 and store into another array of the same size.
	for(int i=0;i<5;i++){
		numbersMultipliedBy2[i]=numbers[i]*2;
	}
	//b. Merge the two arrays into third array
	for(int i=0;i<5;i++){
		mergeNumbers[i]=numbers[i];
	}
	int c=5;
	for(int i=0;i<5;i++){
		mergeNumbers[c]=numbersMultipliedBy2[i];
		c++;
	}
	cout<<"\nAll numbers:\n";
	for(int i=0;i<10;i++){
		cout<<mergeNumbers[i]<<" ";
	}
	
	cin >> numbers[0];
	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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog