(Solved) : Q1 12 Marks Write C Function Sequentially Adds 2 Vectors B C B Use Function Header Void A Q44133439 . . .
![Q1. [12 marks] Write a C function that sequentially adds 2 vectors A and B as C[i] = A[i] + B[i]. Use this function header: v](https://media.cheggcdn.com/media/dde/dde3d36a-6a23-45df-84fc-9abf6586e99a/phpnwztwb.png)
Q1. [12 marks] Write a C function that sequentially adds 2 vectors A and B as C[i] = A[i] + B[i]. Use this function header: void addVec(int* C, int* A, int* B, int size), where size is the number of elements in a vector. You should not create any additional local variables in the function (hint: use pointers and pointer expressions). Test your function with two vectors, each having 50 million integers, all initialized to 0 (hint: calloc). Note that memory allocation for A, B, and C is done within your test code (the main function). Print the first 10 elements of C as well as the total time the function took to complete. Report the results as a comment in your code. Sample run 1: (successful) 0 0 0 0 0 0 0 0 0 0 Execution time: 281.0 ms Sample run 2: (unsuccessful memory allocation) Not enough memory. Marking: +6 for the function, +5 for the test code (2 marks for error checking), +1 for the comment) Show transcribed image text Q1. [12 marks] Write a C function that sequentially adds 2 vectors A and B as C[i] = A[i] + B[i]. Use this function header: void addVec(int* C, int* A, int* B, int size), where size is the number of elements in a vector. You should not create any additional local variables in the function (hint: use pointers and pointer expressions). Test your function with two vectors, each having 50 million integers, all initialized to 0 (hint: calloc). Note that memory allocation for A, B, and C is done within your test code (the main function). Print the first 10 elements of C as well as the total time the function took to complete. Report the results as a comment in your code. Sample run 1: (successful) 0 0 0 0 0 0 0 0 0 0 Execution time: 281.0 ms Sample run 2: (unsuccessful memory allocation) Not enough memory. Marking: +6 for the function, +5 for the test code (2 marks for error checking), +1 for the comment)
Expert Answer
Answer to Q1. [12 marks] Write a C function that sequentially adds 2 vectors A and B as C[i] = A[i] + B[i]. Use this function head…
OR