This is a simple project to print the dot product of two int

This is a simple project to print the dot product of two integer array of size N, where N is provided by user as input and can be very large. The input format is like this: where the first number is N, then followed by one line of input with N numbers, which is the first array; it will then read in another line of input with N numbers, which is the second array; The dot product of two arrays A and B is defined as: For the above example, the dot product is 1 x 4 + 2 x 5 + 3 x 6 + 4 x 7 = 50 You code need to be able to run multiple times, until the user input N as a negative number You must create two functions: 1) ReadInput will create an array based on the argument, then read in all elements of an array; 2) DotProduct to find the dots product of two arrays. All these functions should be declared in a header file, and implemented in a source file. Each run, you need to get N from the user, then call ReadInput twice, DotProduct once and print the result. You need to turn in three files makefile, main.C, xArray.C, xArray.h.

Solution

//xArray.c


int* ReadInput(int n){
int *a[n];
for(int i=0;i<n;i++){
scanf(\"%d\",&a[i]);
}
return a;
}

int* DotProduct(int*a , int* b, int length){
long int* ans;
for(int i=0;i<length;i++){
ans+=(long int)(a[i]*b[i]);
}
}
//compile xArrayfile and include it as header
//main.c

#include<xArray.h>
#include<stdio>

int main(){
int n;
scanf(\"%d\",n);
int *x=ReadInput(n);
int *y=ReadInput(n);
printf(\"the dot product is=%ld\",DotProduct(x,y,n));

return 0;
}

 This is a simple project to print the dot product of two integer array of size N, where N is provided by user as input and can be very large. The input format

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site