Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2. write sequential C code to add 2 vectors A and B with A i] i * 3 and B[i]=-*3 as Cli] Ali] + B[i].

image text in transcribed

Q2. write sequential C code to add 2 vectors A and B with A i] i * 3 and B[i]=-*3 as Cli] Ali] + B[i]. Also find the sum of all elements in C. Eventually, your code should print the sum (which is 0) as well as the execution time Run your code four times with vector sizes of 1, 10, 50, and 100 million integers. Report the results from these four runs as a comment in your code. (12 marks) Sample run 1: (successful) Sum: 0 Execution time: 0.88 sec Sample run 2: (unsuccessful memory allocation) Not enough memory Notes: Lookup the function clock) from time.h Create your arrays using the syntax: int* the number of integers in the array R. Write code to print the error message if the operating system fails to allocate memory to your arrays, in which case malloc will return NULL R (int*) malloc (n sizeof(int)), where n is * = Marking Guide: +2 for creating arrays, +2 for error checking, +2 for rest of code, +2 for time computation, +4 for reporting correct results as a comment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Students also viewed these Databases questions