编写程序,进行三角函数计算
时间: 2023-05-25 13:03:17 浏览: 52
以下是Python中三角函数计算的示例程序:
```python
import math
# 计算正弦函数值
print(math.sin(math.pi / 6))
# 计算余弦函数值
print(math.cos(math.pi / 6))
# 计算正切函数值
print(math.tan(math.pi / 6))
# 计算反正弦函数值
print(math.asin(0.5))
# 计算反余弦函数值
print(math.acos(0.5))
# 计算反正切函数值
print(math.atan(0.5))
```
输出:
```
0.49999999999999994
0.8660254037844386
0.5773502691896257
0.5235987755982989
1.0471975511965979
0.4636476090008061
```
相关问题
编写程序计算三角形的面积
计算三角形面积的公式为:$S=\frac{1}{2}bh$,其中$b$表示三角形底边长,$h$表示三角形高。
你可以使用输入函数来获取用户输入的底边长和高,然后计算出三角形的面积。具体代码如下(以Python为例):
```python
b = float(input("请输入三角形底边长:"))
h = float(input("请输入三角形高:"))
area = 0.5 * b * h
print("三角形的面积为:", area)
```
输入底边长和高后,程序会自动计算出三角形的面积并输出结果。
用c写个三角函数计算程序
好的,以下是一个用 C 语言编写的三角函数计算程序:
#include <stdio.h>
#include <math.h>
int main() {
double angle, sin_value, cos_value, tan_value;
printf("请输入角度值:");
scanf("%lf", &angle);
sin_value = sin(angle * M_PI / 180.0);
cos_value = cos(angle * M_PI / 180.0);
tan_value = tan(angle * M_PI / 180.0);
printf("sin(%lf) = %lf\n", angle, sin_value);
printf("cos(%lf) = %lf\n", angle, cos_value);
printf("tan(%lf) = %lf\n", angle, tan_value);
return 0;
}
该程序可以计算输入角度值的正弦、余弦和正切值。其中,M_PI 是 math.h 库中定义的圆周率常量。