Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that does basic vector operations. You will write a function to

ID: 3623914 • 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.
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. : 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

#include<stdio.h>

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;i<size;i++)

scanf("%d",&arr1[i]);

printf("What is your second vector (x, y, z)?");

for(i=0;i<size;i++)

scanf("%d",&arr2[i]);

printf(" Enter 1 for the sum.");

printf(" Enter 2 for the dot product.");

printf(" Enter 3 for the cross product.");

printf(" Enter 4 for the angle between your vectors");

printf("What would you like to do?");

scanf("%d",&choice);

switch(choice)

{

case 1:printf("Sum of Your vectors is(");

for(i=0;i<size;i++)

printf("%d,",arr1[i]+arr2[i]);

printf(")");

break;

case 2: printf("Dot product of vectors is");

int sum=0;

for(i=0;i<size;i++)

sum=sum+arr1[i]*arr2[i];

printf("%d,",sum);

break;

case 4: printf("Cross product of vectors is (");

cross[0]= arr1[1] * arr2[2] - arr1[2] * arr2[1];

cross[1] = arr1[0] * arr2[2] - arr1[2] * arr2[0];

cross[2] =arr1[0] * arr2[1] - arr1[1] * arr2[0];

for(i=0;i<size;i++)

printf("%d",cross[i]);

printf(")");

break;

default: exit(0);

break;

}

printf("Do you want to continue:")

char con;

scanf("%c",con);

}while(con=='y'||con=='y');

}//end main