Question

Use C Create a function that will take in a vector (three double variables) representing a...

Use C

Create a function that will take in a vector (three double variables) representing a position in meters.

Calculate the magnitude of the vector in meters:

sqrt(x * x + y * y + z * z)

Calculate the magnitude of the vector in feet:

magnitudeInMeters * 3.28084

Using passing by reference, return both outputs from the same function.

Input: Three unique doubles, each one representing a component of the vector.

Output: Magnitude of the vector in meters, magnitude of the vector in feet.

TIP: You will need to #include <math.h> to use the square root function (sqrt).

TIP: You need to use pointers and pass by reference to output both values from the same function.

In your main function:

Prompt the user to enter the X component in meters, followed by the Y component, followed by the Z component.

Call your magnitude calculating function and receive both outputs.

Output the magnitude of the vector in meters.

Output the magnitude of the vector in feet.

NOTE: Your function is required to demonstrate pass by reference

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The following code in C gives you the required functionality:

#include <stdio.h>
#include<math.h>
void mag_cal(double* mag_met, double* mag_fet,double x, double y, double z );
int main(void)
{
double x,y,z;
double mag_met, mag_fet;
printf("Enter the X component, Y component and Z component in meters, respectively: ");
scanf("%lf%lf%lf",&x,&y,&z);
mag_cal(&mag_met,&mag_fet,x,y,z);
printf("Magnitude of vector in meters: %lf\n",mag_met);
printf("Magnitude of vector in feet: %lf\n",mag_fet);
return 0;
}//end of main function

void mag_cal(double* a, double* b,double x, double y, double z )
{
*a = sqrt(x*x + y*y + z*z);
*b = 3.28084 * (*a);
}//end of calculate magnitude function

Code's output:

Enter the X component, Y component and Z component in meters, respectively: 1 1 1 Magnitude of vector in meters 1.732051 MagnHope it helps, do give your valuable response.​

Add a comment
Know the answer?
Add Answer to:
Use C Create a function that will take in a vector (three double variables) representing a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this exercise, you will create a function trough_plot which will plot the cross-section of a...

    In this exercise, you will create a function trough_plot which will plot the cross-section of a trough outlines by the functions y0 and y. Input variables: x – a vector representing the x co-ordinates for the outline of the trough. y – a vector representing the y co-ordinates for the bottom of the trough. y0 – a vector representing the y co-ordinates for the top of the trough. Output variable: n/a – this function has no output variables. Process: The...

  • Create a C program that: Within main, declares a linear array consisting of 10 double values....

    Create a C program that: Within main, declares a linear array consisting of 10 double values. You can assign values to the array when it is declared or fill them items manually using scanf () - your choice. Also, declare three doubles: min, max, and average. Then from within main, a function is called. The function should take a pointer to the array declared above and then finds the maximum value, the minimum value, and calculates the average of the...

  • Please solve the question clearly so I can read your handwriting. Thanks, Consider the function representing...

    Please solve the question clearly so I can read your handwriting. Thanks, Consider the function representing the temperature field T(x,y,z) = 2e22 cos TX – 10y Find the following: (i) the direction in which the temperature T is increasing most rapidly at point P(-1,1,0) and the magnitude of the rate of increase; (ii) the unit vector normal to the level surface T(x, y, z) = -12 at point P(-1,1,0); (iii) the rate of change of the temperature T at point...

  • Ah arbnrary number nents, and all 2-companents separately to f of vector ately to find x-, y"r z-...

    how do you do 7 and 8 ? ah arbnrary number nents, and all 2-companents separately to f of vector ately to find x-, y"r z-components of the resultant vector. B) Break the (given) vectors down into their x-, y, and 2-componerto c) Combine total x, y-, and z-components using Pythagorean Thetee sine the resultant vector and use tangent to determine its angle. and cosines nd the magnitude of Graphical Representation of Vectors You will need o ruler, graph poper,...

  • MATLAB Any guidance is appreciated! Use meshgrid() function to create 2D grid coordinates with x- and...

    MATLAB Any guidance is appreciated! Use meshgrid() function to create 2D grid coordinates with x- and y- coordinates both from -12 to +12 in the increment 1/32. B) Calculate the function z shown below at every (x, y) point and store the result in a 2D array z Z = sin(squareroot x^2 + y^2)/ squareroot x^2 + y^2 c) Find the maximum value in array z and its corresponding index. The array may have more than one maximum points with...

  • code in C++ Create a program that uses the pass by reference operator instead of the...

    code in C++ Create a program that uses the pass by reference operator instead of the return command. Your main program will need to: create empty variables call void function 1 with no input to display your name to the screen call function 2 to collect the square feet that a gallon of paint covers from user call function 2 to collect the square feet of wall that needs to be painted call function 3 to calculate the number of...

  • Implement the sort procedure from Assignment 18 as a void function. Pass the address of the...

    Implement the sort procedure from Assignment 18 as a void function. Pass the address of the first array element to the function along with the number of elements in the array. Use pointers in your function to reference the array elements. The sort function should do nothing but sort the elements of the array. DO NOT pass the entire array as an argument to the function. As in Assignment 18, print out the array before and after sorting. Use the...

  • Name of All Group members Section At the end of this activity you will be able...

    Name of All Group members Section At the end of this activity you will be able to: a. Add and Subtract vectors b. Resolve vectors into horizontal and vertical components c. Apply vector components to solve kinematic problems. Rank the magnitudes of the vectors from greatest to least. If two or more vectors have the same magnitude, the sequence in which you list them does not matter. 7Least Greatest 1 2 3 , 4 2. List all of the vectors...

  • matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number...

    matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number of soldiers each line 2. (char)A file name, indluding extension, for the output file group number Formation1.txt: 1 Line 1 has the following line up: e 1 1 1 0 File Outputs: 21 Line 2 has the folloOwing line up: 1 1 1 1 1 1. A text file showing the soldiers formations 3 Line 3 has the following line up: e e 1...

  • matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number...

    matlab Example: Function Name: battleFormation formation([3 5 11, formation1.txt) Inputs: (double) 1xN vector of the number of soldiers each line 2. (char)A file name, indluding extension, for the output file group number Formation1.txt: 1 Line 1 has the following line up: e 1 1 1 0 File Outputs: 21 Line 2 has the folloOwing line up: 1 1 1 1 1 1. A text file showing the soldiers formations 3 Line 3 has the following line up: e e 1...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT