In: Computer Science
THE FOLLOWING IS CODED IN C
Write a function that sets each element in an array to the sum of the corresponding elements in two other arrays.
That is, if array 1 has the values 2,4, 5, and 8 and array 2 has the values 1, 0, 4, and 6, the function assigns array 3 the values 3, 4, 9, and 14.
The function should take three array names and an array size as arguments.
Test the function in a simple program (i.e., in main, create three arrays, put values into two of them, call the function to get the sum array. Show reasonable output).
Submit the whole program containing the main method and the function as specified.
#include <stdio.h>
void sumArray(int array_1[],int array_2[],int array_3[],int
n)
{
int i;
for(i=0;i<n;i++)
array_3[i]=array_1[i]+array_2[i];
}
int main()
{
int num, c, d, array_1[100],array_2[100],array_3[100];
printf("Enter the number of elements in array: ");
scanf("%d", &num);
printf("Enter the first array elements\n");
for (c = 0; c < num ; c++)
scanf("%d", &array_1[c]);
printf("Enter the second array elements\n");
for (c = 0; c < num ; c++)
scanf("%d", &array_2[c]);
sumArray(array_1,array_2,array_3,num);
for(int i=0;i<num;i++)
printf("%d ",array_3[i]);
}