Answer:
#include<stdio.h>
int dot_product(int a[],int b[],int n) // function definition which
takes the arguments as two vectors a, b, and number of elements n
in the vectors
{
int i,dp=0; // i is a counter variable, and dp is the
variable to hold the dot product (i and dp are different from i and
dp of main()
for(i=0;i<n;i++)
{
dp=dp+(a[i]*b[i]); // calculating
dot product dp by multiplying ith element of vector a and ith
element of vector b
}
return dp; //returning the value of dp to main() function
}
int main()
{
int a[10],b[10];// a, b are the arrays to store the
vector elements
int i,dp,n; // i is a counter variable, n is the
number of elements of the arrays, and dp is the variable to hold
the dot product
printf("Enter the number of elements of the
vector:");
scanf("%d",&n); // read the value of n i.e
elements of arrays
printf("Enter the elements of vector a\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]); // taking
the elements into array a
}
printf("Enter the elements of vector b\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]); // taking
the elements into array b
}
dp=dot_product(a,b,n); // call to the function
dot_product() by passing the arguments array a, array b, and number
of elements n
printf("The dot product of two vector is:%d",dp); //
printing the dot product value dp
return 0;
}
Output:
NOT C++ Write a C function named dot_product to calculate the dot product of two vectors...
in c++ Write a program which can find the dot product of two vectors of the same length ?. The user will enter the length ?. Use the length to control how many times you loop. The result is a scalar value and not a vector. If the dot product is zero, then the two vectors are perpendicular.
Problem 2: Matrix Vector Operationsa) Create a program named my_dotProduct which USING LOOPS calculates the dot product of two vectors (of dimensions \(1 \times n\) ) from the keyboard. The program should check the input from the user making sure that the vectors are the right dimensions. If the vectors are not then an error message should be outputted to the user. If the vectors are of the right dimensions then the answer should be outputted to the user. Using...
Write a C program to do the following: 1. Write a C function named find that receives a one-dimensional array of type character named arr and its size of type integer. After that, the function must select a random index from the array. The function must find if the character stored in the randomly selected index comes before all the characters to its left alphabetically. Finally, the function prints to the screen the element if the element meets the condition...
C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...
use C++ Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse any given word. 2. Write a program that will: Ask the user to enter a word. Save the entry as word_entered. Call word_rev on the entry Display the reversed entry (word_entered) 3. Write a function named prime() that determine whether or not a given number n (greater than one) is prime. The algorithm: If n is even then n is not a prime number...
Please write the code using matlab
1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...
Question 4.4: Write an overloaded function of function area with 3 (float) parameters. This function should calculate and print out the product of the 3 parameters. Question 4.4: Write the main function to test question 4.1, 4.2, 4.3, 4.4. Your main function should ask if the user want to calculate the area of a rectangle or a circle or a triangle then print out the result accordingly. (Use switch structure). For example: Please enter (r) for rectangle, (t) for triangle,...
"PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes two parameters, the filename and an effect. c. Take a picture with the filename and effect. Use camera.effect to set the effect. Use help(PiCamera) to find the effects which you can apply. d. Create a second file use_camera.py. e. Import the take_picture_effect function from the camera_picture module. f. Prompt the user for the filename. g. Prompt the user for the image_effect. help(PiCamera) to see...
C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers using Euclid’s algorithm (also known as the Euclidean algorithm). Write a main () function that requests two integers from the user, calls your function to compute the GCD, and outputs the return value of the function (all user input and output should be done in main ()). In particular, you will find this pseudocode for calculating the GCD, which should be useful to you:...
In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...