C++ programing Write a program that adds the contents of the two arrays with 4 i
ID: 3686355 • Letter: C
Question
C++ programing
Write a program that adds the contents of the two arrays with 4 input at each position and store it into a third array. For example, if A1 = {1, 2, 3, 4} and A2 = {5, 3, 7, 2} the sum of the two will be A3 = {6, 5,10, 6}. Print the contents of the summed array to the console. Write a program that follows bellow steps: Declare array A of 15 integers. Initialize the whole array A to 0 by for loop. Declare array B of 15 integers. Initialize the whole array B to ascending numbers starts from 1 to 15 by for loop. (1, 2, 3,4,5,6,...,15) Update array A members' value by following rule: If i = even rightarrow A[i] = B[i].Explanation / Answer
1.
#include<iostream.h>
#include<stdlib.h>
void main()
{
int i,A1[]={1,2,3,4},A2[]={5,3,7,2},A3[4];
for(i=0;i<4;i++)
{
A3[i]=A1[i]+A2[i];
}
cout<<"Summed array is:"<<endl;
for(i=0;i<4;i++)
{
cout<<A3[i]<<endl;
}
system("pause");
}
2.
#include<iostream.h>
#include<stdlib.h>
void main()
{
int i,A[15],B[15];
for(i=0;i<15;i++)
{
A[i]=0;
}
for(i=0;i<15;i++)
{
B[i]=i+1;
}
for(i=0;i<15;i++)
{
if(i%2==0)
A[i]=B[i];
}
cout<<"Array is:"<<endl;
for(i=0;i<15;i++)
{
cout<<A[i]<<endl;
}
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.