Using C++ Write a programmer defined function to add the elements of two arrays
ID: 3816264 • Letter: U
Question
Using C++
Write a programmer defined function to add the elements of two arrays of 5 integers each. Your main function should declare three integer arrays—two for holding the elements to be added and 1 for holding the sum, and ask the user the enter the value for the first two arrays. Then, you need to call your programmer defined function and pass the three arrays to it. Now your function needs to compute the sum from the elements of the first two array and store in the third array. Display the elements of the sum array that in your main function.
Explanation / Answer
code:
#include <iostream>
#include <stdlib.h>
using namespace std;
void sum(int arr1[],int arr2[],int arr3[])
{
int i=0;
for(i=0;i<5;i++)
{
arr3[i] = arr1[i]+ arr2[i];
}
}
int main()
{
int arr1[100];
int arr2[100];
int arr3[100];
cout<<"enter first array:"<<endl;
int i=0;
for(i=0;i<5;i++)
{
cin>>arr1[i];
}
cout<<"enter second array:"<<endl;
for(i=0;i<5;i++)
{
cin>>arr2[i];
}
sum(arr1,arr2,arr3);
cout<<"content of third array is: "<<endl;
for(i=0;i<5;i++)
{
cout<<arr3[i]<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.