Question: 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:

 Q1. [12 marks] Write a C function that sequentially adds 2

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)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!