曲径通幽论坛

标题: sin() -- 计算正弦值 [打印本页]

作者: beyes    时间: 2011-12-23 23:55
标题: sin() -- 计算正弦值
sin() 原型如下:
[Plain Text] 纯文本查看 复制代码
#include <math.h>
double sin(double x);

sin() 用来计算参数 x 的正弦值,然后返回结果,结果范围为 -1 ~ 1 之间。 参数 x 是弧度表示,比如你要计算的是角度,那么先要进行转换。比如要计算 30° 角度的值,转换成弧度,公式为 (30*π)/180 。

测试代码
[C++] 纯文本查看 复制代码
#include <stdio.h>
#include <math.h>

int main()
{
    printf("%f\n", sin((3.14159*30)/180));       /* 计算 sin(30°) */

    return 0;
}

运行输出:
./sin
0.500000





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2