Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C programming (pls lable which file is libvector.h and libvector.c) Q3) Write a function that takes two arrays and their size as inputs, and

Use C programming (pls lable which file is libvector.h and libvector.c)

Q3) Write a function that takes two arrays and their size as inputs, and calculates their inner product (note that both arrays must have the same size so only one argument is needed to specify their size). The inner product of two arrays A and B with N elements is a scalar value c defined as follows:

N1 c=AB= A(i)B(i)=A(0)B(0)+A(1)B(1)++A(N1)B(N1),

i=0

where A(i) and B(i) are the ith elements of arrays A and B, respectively. For example, theinnerproductofA=(1,2)andB=(3,3)isc1 =9;andtheinnerproductofC= (2,5,4,2,1) and D = (3,4,2,0,2) is c2 = 36.

You must use the following function prototype:

 int innerProduct(int A[], int B[], int size); 

Note: You must write your function prototype in a header file named libvector.h and you must write your function definition in a source file named libvector.c. We are providing you the main source file vector.c, which you can use to test your function. Do not change anything in vector.c.

vector.c

#include #include #include "libvector.h"

int main() { int* array1; int* array2; int n, c, result;

printf("Enter number of elements: "); scanf("%d", &n);

/* dynamic memory allocation */ array1 = (int*) malloc(n * sizeof(int)); array2 = (int*) malloc(n * sizeof(int));

printf("Enter the %d elements of vector A: ", n);

for (c = 0; c < n; c++) scanf("%d", &array1[c]);

printf("Enter the %d elements of vector B: ", n);

for (c = 0; c < n; c++) scanf("%d", &array2[c]);

result = innerProduct(array1, array2, n);

printf("The inner product of vectors A and B is: %d. ", result);

return 0; }

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago