C++调用三角函数库之前,需要引入头文件#include
#include#include using namespace std; #define PI 3.1415926535898 int main() { float x; float y; x = sin(30*(PI/180)); y = cos(60 * (PI / 180)); cout << x << endl; cout << y << endl; }
调用三角函数时,需要将角度转化为弧度。
常用函数:
abs 绝对值函数
sin 正弦函数
cos 余弦函数
tan 正切函数
asin 反正弦函数
acos 反余弦函数
atan 反正切函数
exp e的次方
pow 次幂
sqrt 开方