Write a C++ function which accepts two array of integers (like arr1 and arr2) of the same size (100), then create a new array (like arr3) with the same size (100) and assign the sum of corresponding elements in arr1 and arr2 to the new array (arr3) and return back arr3 from the function. You don't need to write the main function.
For example sum of corresponding elements in arr1 and arr2 to be assigned to arr3 should be like:
arr3[0] = arr1[0]+arr2[0]
arr3[1] = arr1[1]+arr2[1]
Here since you don't want the main function here, this means you only want the code without showing the entire program.
Let's see how to write the function.
Here since the function should return array, basically it will return pointer to the array. Therefore the function declaration will be like
int * add_Array(int [] , int [])
Let's write the complete function.
int * add_Array (int arr1[] , int arr2[])
{
int arr3[100];
for(int i=0; i<100 ; i ++)
{
arr3[i] = arr1[i] + arr2[i];
}
return arr3; //returning the base address which is also the pointer
}
This is how the function is to be written. If you need the entire code, let me know.
If you have any questions comment down and please? upvote thanks...
Get Answers For Free
Most questions answered within 1 hours.