Please help me to do this on C program: Write a function named VectorPlusVector
ID: 3805077 • Letter: P
Question
Please help me to do this on C program:
Write a function named VectorPlusVector to compute the element by element sum of two vectors. The desired output is a vector, but since we can't output a vector from a C function, we will declare the results vector as a global variable. Inputs: 1. Input vector 1 (double) 2. Input vector 2 (double) 3. Length of vectors (int) Output: None! (See explanation above.) Function pseudocode: Use a for loop to add each element in input vector 1 to the corresponding element in input vector 2 and assign the sum to the corresponding element in the global results vector. Prototype your function above main() so that the function itself can come after main(). Intrusions for main(): Call your function from main() with {1.1, 2.1, 3.1, 4.1, 5.1} and {1.5, 1.4, 1.3, 1.2, 1.1} as the input vectors, and a length of 5. Use printf inside a for loop to print the values of the results vector.Explanation / Answer
/*Problem 10.C */
#include<stdio.h>
#include<conio.h>
#define len1 5
#define len2 5
double Vector[100];
void VectorPlusVector(double[],double[]);
void main()
{
double Vector1[len1] = {1.1,2.1,3.1,4.1,5.1};
double Vector2[len2] = {1.5,1.4,1.3,1.2,1.1};
clrscr();
printf("Practise Problem 10.2");
VectorPlusVector(Vector1,Vector2);
getch();
}
void VectorPlusVector(double Vec1[],double Vec2[]){
int i;
printf(" The new Vector is:");
for(i=0;i<len1;i++){
Vector[i] = Vec1[i] + Vec2[i];
printf("%f ",Vector[i]);
}
}
/* Sample Input and Output */
Practise Problem 10.2
The new Vector is: 2.6 3.5 4.4 5.3 6.2