Answered step by step
Verified Expert Solution
Question
1 Approved Answer
this is to be written in C programming. I am new so please keep things fairly simple (dont use arrays and strings, use descriptive variable
this is to be written in C programming. I am new so please keep things fairly simple (dont use arrays and strings, use descriptive variable names). Also please do both exersises as it is apart of a series. Thanks
Part 2 3.1 Exercise 4: Define function read_vector Complete the missing function read vector below, which takes three pointers to float values as arguments. The function should read three floating point values from the user and store the result in the destination of the three pointers. If all values can be read successfully, the function will return 1. Otherwise (if any values cannot be read), the function will return 0. When the function works correctly, running the program will prompt the user to enter two vectors and then print those vectors back out. Do not modify the main function. #include below is the template for 3.2:
#include
#include
// Purpose: Computes the dot product of the vectors (x1, y1, z1) and (x2, y2, z2)
// Args: float x1, float y1, float z1, float x2, float y2, float z2
// Returns: float - the dot product
float dot_product( float x1, float y1, float z1, float x2, float y2, float z2 ){
//Your code here
}
/*
* Purpose: Computes the cross product of the vectors (x1, y1, z1) and (x2, y2, z2)
* and stores the result using the pointers result_x, result_y and result_z
* Args: float x1, float y1, float z1, float x2, float y2, float z2,
* float* result_x, float* result_y, float* result_z
*/
void cross_product( float x1, float y1, float z1,
float x2, float y2, float z2,
float* result_x, float* result_y, float* result_z){
//Your code here
}
// Purpose: Computes the norm of the vector (x, y, z)
// Args: float x, float y, float z
// Returns: float - the norm
//You may want to use the sqrt() function from math.h
/otice that it is included above and instructions for use in CLion below.
float norm( float x, float y, float z ){
//Your code here
}
int main(){
float x1, y1, z1;
float x2, y2, z2;
float x3, y3, z3;
x1 = 1;
y1 = 2;
z1 = 3;
x2 = 4;
y2 = 5;
z2 = 6;
float d = dot_product(x1,y1,z1, x2,y2,z2);
cross_product(x1,y1,z1, x2,y2,z2, &x3,&y3,&z3);
float n1 = norm(x1,y1,z1);
float n2 = norm(x2,y2,z2);
printf("v1 = (%f %f %f) ", x1, y1, z1);
printf("v2 = (%f %f %f) ", x2, y2, z2);
printf("v1 (dot) v2 = %f ", d);
printf("v3 = v1 x v2 = (%f %f %f) ", x3, y3, z3);
printf("norm(v1) = %f ", n1);
printf("norm(v2) = %f ", n2);
//Since (x3, y3, z3) is the cross product of v1 and v2, it should be
//orthogonal to both v1 and v2 (so the dot product should be zero).
float d13 = dot_product(x1,y1,z1, x3,y3,z3);
float d23 = dot_product(x2,y2,z2, x3,y3,z3);
printf("v1 (dot) v3 = %f ", d13);
printf("v2 (dot) v3 = %f ", d23);
return 0;
}
the output should be as follows:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started