cosh() Function Example in C Programming

In this source code example, we will see how to use the cosh() function in C programming with an example.

cosh() Function Overview

The cosh() function in C calculates the hyperbolic cosine of a given number. Like its counterpart, the sinh() function, the cosh() function deals with hyperbolic angles rather than circular ones.

It is frequently used in various areas of engineering, physics, and mathematics, especially when working with hyperbolic functions. The function is part of the math.h library. 

Key Points

- To utilize the cosh() function, you should include the math.h header. 

- The argument passed can be any real number. 

- When compiling, remember to link the math library using the -lm flag.

Source Code Example

#include <stdio.h>
#include <math.h>  // Required for cosh()

int main() {
    double value, result;

    // Get the value from the user
    printf("Enter a value to compute its hyperbolic cosine: ");
    scanf("%lf", &value);

    // Calculate the hyperbolic cosine of the value
    result = cosh(value);

    // Display the result
    printf("Hyperbolic cosine of %.2lf is: %.2lf\n", value, result);

    return 0;


Enter a value to compute its hyperbolic cosine: 1
Hyperbolic cosine of 1.00 is: 1.54


1. We commence by including the necessary header files: stdio.h for standard input/output operations and math.h for mathematical functions like cosh().

2. Within the main() function, we ask the user to provide a value.

3. We then use the cosh() function to determine the hyperbolic cosine of the input value.

4. Finally, the computed result is printed on the console.