C cos()

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
你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战