C51 函数cos()与acos()使用注意点
–2022.03.02 J
1)cos()函数与acos()函数定义
double acos(double x);
acos() 函数的功能是求反余弦值,即求角度。
double cos(double x);
cos() 函数的功能是求某个角的余弦值。
2)注意点:
z=acos(x)和x=cos(y),一定要注意这里的y、z是弧度值。在C51程序设计时,如果想求30°的余弦,反余弦,则需要进行弧度与角度之间的转换。
30°的弧度:y= 30* PI / 180.0; x=cos(y);
z=acos(x); //z是弧度值,不是30度,需要将弧度转换为角度;
30°=z* 180.0 / PI;
3) 例程:
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
int main ()
{
double test,result,x, y,z;
test = 30.0;
y=test*PI/180.0;
x=cos(y);
printf (" %f ° 的cos is %f.\n", test, x );
z=acos(x);
result=z*180.0/PI;
printf ("test is %f °;result is %f°.\n", test, result );
return 0;
}