sin() 函数定义在 math.h 头文件中。它有助于返回给定弧度值的正弦值。
double sin(double x) #where x can be in int, float or long double
sin() 函数接受一个参数,该参数是一个表示以弧度表示的角度的值。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 双精度浮点数值 | 一个 double 类型的值,表示以弧度表示的角度 | 必需 |
sin() 函数的返回值为介于 1 和 -1 之间的数字。
| 输入 | 返回值 |
|---|---|
| -1 < x ≥ 1 | 一个大于或等于 0 的数字 |
| x < -1 | NaN (非数字) |
#include <stdio.h>
#include <math.h>
int main()
{
double v;
double output;
v = 2.3;
output = sin(v);
printf("sin(%.2lf) = %.2lf\n", v, output);
v = -2.3;
output = sin(v);
printf("sin(%.2lf) = %.2lf\n", v, output);
v = 0;
output = sin(v);
printf("sin(%.2lf) = %.2lf\n", v, output);
return 0;
}
输出
sin(2.30) = 0.75 sin(-2.30) = -0.75 sin(0.00) = 0.00
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main () {
double v, out, value;
v = 45.0;
value = PI / 180;
out = sin(v*value);
printf("The sine value of %lf is %lf degrees", v, out);
return(0);
}
输出
The sine value of 45.000000 degrees is 0.707107