Mat*_*att 9 c++ math trigonometry
我试图在C++中进行简单的三角计算.以下是我遇到的问题的一个例子.据我所知,C++以弧度工作,而不是度.因此,从弧度到度数的转换应该是乘以180并除以pi的简单情况.一个简单的测试是tan(45),它应该等于1.以下程序产生的值为92.8063但是......
#include <iostream>
using namespace std;
#include <math.h>
int main(){
double a,b;
a = tan(45);
b = a * 180 / 3.14159265;
cout << b;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
的角度是输入到tan.所以你要:
a = 45 * 3.141592653589793 / 180.0;
b = tan(a);
cout << b << endl;
Run Code Online (Sandbox Code Playgroud)