write a program that does basic vector operations. You will write a function to
ID: 3624015 • Letter: W
Question
write a program that does basic vector operations. You will write a function to perform each operation, using arrays and loops as necessary. You may leave all the functions in the same file as main for this homework, but they must be declared before they can be called within main. Specifically, your program should do the following:1. Prompt the user to enter the x, y, and z values for two vectors (a and b), and store them in arrays.
2. Ask the user what operation he would like the program to perform.
3. The program should then call the function to perform one of the following operations: add the vectors (a+b), find the dot product, find the cross product (axb), and find the angle between them. (go review your math book if you don’t remember how vectors work)
4. The program should then display the value requested by the user, or display an error message if the user typed something in wrong.
5. Extra Credit (20 points): Ask the user to enter a vector length before entering their vectors (step 1 above). Have the user enter their vectors, and do error checking to make sure they entered the correct number of vector elements. Write your functions so that they can perform the math on any length array. Make the program loop by asking the user if they have another vector (stop if they don’t say “y” or “Y”).
You must use a for loop for at least one of the operations, and your vectors must be stored and passed as arrays.
Example outputs (with user input underlined) are:
What is your first vector (x, y, z)? 1,0,0
What is your second vector (x, y, z)? 0,1,0
Here are your options:
Enter 1 for the sum.
Enter 2 for the dot product.
Enter 3 for the cross product.
Enter 4 for the angle between your vectors.
What would you like to do? 4
The angle between your vectors is 1.57 radians.
What is your first vector (x, y, z)? 2,3,2
What is your second vector (x, y, z)? 1,-1,5.3
Here are your options:
Enter 1 for the sum.
Enter 2 for the dot product.
Enter 3 for the cross product.
Enter 4 for the angle between your vectors.
What would you like to do? 1
The sum of your vectors is (3.00,2.00,7.30).
Explanation / Answer
Dear, Here is the code #include void main() { int size=3,i,choice; int arr1[size],arr2[size],cross[siz]; printf("What is your first vector (x, y, z)? "); for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.