Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started