x = 60.0;
val = PI / 180.0;
ret = cos( x*val );
printf("The cosine of %lf is %lf degrees\n", x, ret);
您好,我在自学 math.h 中的函数,然后我尝试使用 COS 函数在程序中求半径的余弦值。我试图找到这个函数的解释,为什么 COS 函数需要在 Cos 函数中添加 Pi/180.0 才能正确计算半径的 cos。非常感谢你
最佳答案
如果您检查 documentation ,您会看到 cos()
接受以弧度为单位的角度,而不是度数。将 60 度角乘以 PI/180.0
,即可将其转换为弧度。
关于c - 为什么我必须声明常量 Pi 值才能在 Math.h 中使用 Cos 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47104840/