I need help to write a C++ program to sum the content of two arrays arrayA and a
ID: 3686069 • Letter: I
Question
I need help to write a C++ program to sum the content of two arrays arrayA and arrayB and store the sum in a third array arrayC.
Use the following 3 functions:
1- Functionvoid read (int arrayA[10] , int arrayB[10]); that asks the user to enter 10 values for each array. Use any loop.
2- Functionvoid sum(int arrayA[10] , int arrayB[10], int arrayC[10] ); for example, sums the value stored in the first cell of arrayA with the value stored in first cell of arrayB and stores it in the first cell of arrayC
3-Function void print(int anArray[10]); that prints the content of an array
In the main program;
1-Declare all arrays to be of type int and each can hold 10 integers.
2-Call the function read
3-Call the function sum
4-Print the content of arrayA , arrayB , arrayB arrayC by calling function print for each array.
Thank You!
Explanation / Answer
// Example program
#include <iostream>
#include <string>
using namespace std;
void read (int A[10],int B[10])
{
int i,j;
cout<<"Please enter ten numbers for Array A"<<endl;
for(i=0;i<10;i++)cin>>A[i];
cout<<"Please enter ten numbers for Array B"<<endl;
for(i=0;i<10;i++)cin>>B[i];
return;
}
void sum(int A[10],int B[10],int C[10])
{
for(int i=0;i<10;i++)C[i]=A[i]+B[i];
return;
}
void print(int A[10])
{
for(int i=0;i<10;i++)cout<<A[i]<<' ';
cout<<' ';
return;
}
int main()
{
int A[10],B[10],C[10];
read(A,B);
sum(A,B,C);
print(A);
print(B);
print(C);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.