sinh(), cosh() and tanh() in C

sinh(), cosh() and tanh() calculate the hyperbolic sine, cosine and tangent of a floating-point value.

Syntax Top ↑

double sinh(double x);
double cosh(double x);
double tanh(double x);

Hyperbolic Values Top ↑

#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.

Preserved Hyperbolic-Function Variations Top ↑

sinh() with User Input

#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;
}

Choose sinh(), cosh() or tanh()

#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;
}




plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer