Asked by jasmine
I am suppose to create a code that uses the pow function in math.h to calculate the hyperbolic cosine when the user inputs an angle x. the equation I have to use is cosh x= e^x + e^-x /2 can someone check my code. I am not sure what i am doing wrong. do I have to declare the constant e as a variable. I am totally lost!
#include <stdio.h>
#include <math.h>
int main (void)
{
//Local Declarations
float angleX; // Angle inputed by the user
//Statements
printf ("\nEnter angle in degrees:");
scanf ("%f", &angleX);
//Results
printf ("\nCalculation1 : (M_E^angleX + M_E^(-angleX))/2 = %f\n", pow(M_E,angleX)); /* calculates
the hyperbolic cosine using the pow function*/
return (0);
}//main
#include <stdio.h>
#include <math.h>
int main (void)
{
//Local Declarations
float angleX; // Angle inputed by the user
//Statements
printf ("\nEnter angle in degrees:");
scanf ("%f", &angleX);
//Results
printf ("\nCalculation1 : (M_E^angleX + M_E^(-angleX))/2 = %f\n", pow(M_E,angleX)); /* calculates
the hyperbolic cosine using the pow function*/
return (0);
}//main
Answers
Answered by
jasmine
#include <stdio.h>
#include <math.h>
int main (void)
{
//Local Declarations
float angleX; // Angle inputed by the user
float coshx; // hyperbolic cosine of angle x
//Statements
printf ("\nEnter angle in degrees:");
scanf ("%f", &angleX);
//Calculations
coshx = (pow(M_E,angleX) + pow( M_E,-angleX))/2;//calculated the hyperbolic cosine using the pow function
//Results
printf ("\nCalculation1 : = %f\n", coshx);
return (0);
}//main
#include <math.h>
int main (void)
{
//Local Declarations
float angleX; // Angle inputed by the user
float coshx; // hyperbolic cosine of angle x
//Statements
printf ("\nEnter angle in degrees:");
scanf ("%f", &angleX);
//Calculations
coshx = (pow(M_E,angleX) + pow( M_E,-angleX))/2;//calculated the hyperbolic cosine using the pow function
//Results
printf ("\nCalculation1 : = %f\n", coshx);
return (0);
}//main
Answered by
jasmine
I changed some things and now it is atleast coming out with a calculation but it is the wrong answer
Answered by
Steve
Hmm. Looks good to me. Can you produce the results for a few values of x?
Do you at least get cosh(0) = 1.0 ?
Do you at least get cosh(0) = 1.0 ?
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.