C 庫 - cosh() 函式



C 庫的 cosh() 函式,型別為 double,接受引數 (x),返回 x 的雙曲餘弦值。在程式中,它用於表示幾何圖形的角度。

雙曲餘弦在工程物理學中使用,因為它出現在溫度成型時金屬棒的熱方程的解中。

語法

以下是 C 庫函式 cosh() 的語法 -

double cosh(double x)

引數

此函式僅接受一個引數。

  • x - 這是一個浮點值。

返回值

此函式返回 x 的雙曲餘弦值。

示例 1

以下是一個基本的 C 庫程式,演示了 cosh() 函式的使用。

#include <stdio.h>
#include <math.h>

int main () {
   double x;

   x = 0.5;
   printf("The hyperbolic cosine of %lf is %lf\n", x, cosh(x));

   x = 1.0;
   printf("The hyperbolic cosine of %lf is %lf\n", x, cosh(x));

   x = 1.5;
   printf("The hyperbolic cosine of %lf is %lf\n", x, cosh(x));

   return(0);
}

輸出

以上程式碼產生以下結果 -

The hyperbolic cosine of 0.500000 is 1.127626
The hyperbolic cosine of 1.000000 is 1.543081
The hyperbolic cosine of 1.500000 is 2.352410

示例 2

我們在 for 迴圈中使用 cosh(),它生成一系列正數的雙曲餘弦值表。

#include <stdio.h>
#include <math.h>

int main() {
   printf("Table of Hyperbolic Cosines:\n");
   for (double x = 0.0; x <= 1.5; x += 0.5) {
       double res = cosh(x);
       printf("cosh(%.2lf) = %.6lf\n", x, res);
   }
   return 0;
}

輸出

執行以上程式碼後,我們得到以下結果 -

Table of Hyperbolic Cosines:
cosh(0.00) = 1.000000
cosh(0.50) = 1.127626
cosh(1.00) = 1.543081
cosh(1.50) = 2.352410

示例 3

下面的程式使用 cosh() 函式查詢實數的雙曲餘弦值。

#include <stdio.h>
#include <math.h>

int main() {
   double x = 0.5;
   double result = cosh(x);
   printf("Hyperbolic cosine of %.2lf (in radians) = %.6lf\n", x, result);
   return 0;
}

輸出

執行程式碼後,我們得到以下結果 -

Hyperbolic cosine of 0.50 (in radians) = 1.127626
廣告

© . All rights reserved.