C语言中 COS()的用法

来源:百度知道 编辑:UC知道 时间:2024/05/15 04:42:38
我想用COS函数 其中d为角度 开始用float定义的 请问cos(180/d)是错误的表达不?180/d结果是整数还是实数? cos()函数有什么要求不?比如括号内是否要整数或者正数?

原型是:double cos( double )
传入的应该是弧度,把度化为弧度,应该是这样的吧:
假设度数为d,则对应的弧度为:d * pi / 180

cos()是库函数,在头文件math.h中,原型是double cos(double x);,其中x要用弧度表示。如求30°的余弦值可用下列代码实现:
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
#include "math.h"
int main(void){
    printf("cos30°= %.10f\n",cos(30*3.1415926535897932/180));
    return 0;
}