用C++编程三角函数计算器
时间: 2023-12-11 16:04:43 浏览: 191
下面是一个简单的C++程序,用于计算三角函数:
```
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double angle;
cout << "请输入角度:";
cin >> angle;
double radians = angle * M_PI / 180.0;
cout << "sin(" << angle << ") = " << sin(radians) << endl;
cout << "cos(" << angle << ") = " << cos(radians) << endl;
cout << "tan(" << angle << ") = " << tan(radians) << endl;
return 0;
}
```
该程序使用了 `<cmath>` 库中的 `sin`、`cos` 和 `tan` 函数,这些函数可以计算给定角度的正弦、余弦和正切值。程序先提示用户输入角度,然后将角度转换为弧度,并计算三角函数的值。运行程序后,用户可以输入任意角度,并得到对应的三角函数值。
阅读全文
相关推荐














