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
#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;
}
Comments
Leave a comment