C cos() 原型
double cos(double x);
函数 cos() 接受一个以弧度为单位的参数,并返回一个 double
类型的值。
cos() 返回的值范围始终是:-1 到 1。
它定义在 <math.h> 头文件中。
[Mathematics] cosx = cos(x) [In C Programming]
为了对浮点数或长双精度数使用 cos(),您可以使用以下原型
long double cosl(long double x); float cosf(float x);
C cos() 范围
传递给 cos() 函数的参数可以是任何值,无论是负数还是正数。
示例:C cos() 函数
#include <stdio.h>
#include <math.h>
#define PI 3.141592654
int main()
{
double arg = 30, result;
// Converting to radian
arg = (arg * PI) / 180;
result = cos(arg);
printf("cos of %.2lf radian = %.2lf", arg, result);
return 0;
}
输出
cos of 0.52 radian = 0.87