(Functions and Pointers) Write a program that will use a function to calculate a
ID: 3686378 • Letter: #
Question
(Functions and Pointers) Write a program that will use a function to calculate and print the value of Y given by the following formula: Y(x) = x^2/2-x lnx
Use the function prototype void Y_function(double *Y_x_ptr, double x );
Use the function in the main to calculate the value of Y for all values of x from 5 to 50, in increments of 5. Use of the natural logarithm math function, which is defined in the math library: double log(double var1 ) which accepts one variable of type double (var1) and calculates its natural logarithm and returns the result as a type double.
Example: ln_x = log(x); //returns the natural log value of x and it is stored in the
//variable ln_x
Explanation / Answer
void Y_function(double *Y_x_ptr, double x )
{
double new_x=pow(x,2);
double new_y=new_x/2-(x*(log (x)));
*Y_x_ptr=new_y;
}
int main()
{
double *Y_x_ptr=NULL;
for(int i=5;i<=5;i=i+5)
{
Y_function(&Y_x_ptr,i);
printf(*Y_x_ptr);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.