#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
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
3 answers
I changed some things and now it is atleast coming out with a calculation but it is the wrong answer
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 ?