Latest web development tutorials

C 庫函數– cos()

C 標準庫 - <math.h> C標準庫- <math.h>

描述

C庫函數double cos(double x)返回弧度角x的餘弦。

聲明

下面是cos() 函數的聲明。

double cos(double x)

參數

  • x --浮點值,代表了一個以弧度表示的角度。

返回值

該函數返回x 的餘弦。

實例

下面的實例演示了cos() 函數的用法。

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

#define PI 3.14159265

int main ()
{
   double x, ret, val;

   x = 60.0;
   val = PI / 180.0;
   ret = cos( x*val );
   printf("%lf 的余弦是 %lf 度\n", x, ret);
   
   x = 90.0;
   val = PI / 180.0;
   ret = cos( x*val );
   printf("%lf 的余弦是 %lf 度\n", x, ret);
   
   return(0);
}

讓我們編譯並運行上面的程序,這將產生以下結果:

60.000000 的余弦是 0.500000 度
90.000000 的余弦是 0.000000 度

C 標準庫 - <math.h> C標準庫- <math.h>