sinh(), cosh() and tanh() calculate the hyperbolic sine, cosine and tangent of a floating-point value.
double sinh(double x);
double cosh(double x);
double tanh(double x);
#include <math.h>
#include <stdio.h>
int main(void) {
double x = 1.0;
printf("sinh(1) = %.6f\n", sinh(x));
printf("cosh(1) = %.6f\n", cosh(x));
printf("tanh(1) = %.6f\n", tanh(x));
return 0;
}
These are hyperbolic functions, not ordinary trigonometric functions. Their argument is not interpreted as an angle in degrees.
#include <math.h>
#include <stdio.h>
int main(void) {
double value;
printf("Enter a number: ");
if (scanf("%lf", &value) != 1) {
printf("Invalid input.\n");
return 1;
}
printf("sinh(%.2f) = %.6f\n", value, sinh(value));
return 0;
}
#include <math.h>
#include <stdio.h>
double calculate_hyperbolic(char type, double value) {
if (type == 's') {
return sinh(value);
}
if (type == 'c') {
return cosh(value);
}
return tanh(value);
}
int main(void) {
char type;
double value;
printf("Enter s for sinh, c for cosh, or t for tanh: ");
if (scanf(" %c", &type) != 1 ||
(type != 's' && type != 'c' && type != 't')) {
printf("Invalid choice.\n");
return 1;
}
printf("Enter a number: ");
if (scanf("%lf", &value) != 1) {
printf("Invalid input.\n");
return 1;
}
printf("Result = %.6f\n",
calculate_hyperbolic(type, value));
return 0;
}
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.