@今天的c语言你学废了吗?!!----解三角形(20210204

@今天的c语言又学废了呢----解三角形

2021-02-04

Triangle
For given two sides of a triangle a and b and the angle C between them, calculate the following properties:
S: Area of the triangle
L: The length of the circumference of the triangle
h: The height of the triangle with side a as a bottom edge
Input
The length of a, the length of b and the angle C are given in integers.
Output
Print S, L and h in a line respectively. The output should not contain an absolute error greater than 10-4.
Sample Input
4 3 90
Sample Output
6.00000000
12.00000000
3.00000000

这题看似简单
直接用高中学的公式
确实很简单

只是坑比较多(就是错了几次而已,真的,几次而已)

1.从精度上看
输入的时候指明了是要用int,但是输出的时候得用double

2.从计算公式来看

1)首先写上<math .h>的头文件

2)用三角函数的时候,需要将角度转化成弧度
… 这就需要在开头的时候定义一下pi
也就是 const double pi = 3.1415926
然后 sin ( x * pi / 180)
【谁能知道高考不过半年,小five竟然需要百度这些共是,实在是裂开,裂开啊】

友好如我,直接列出公式吧(光公式我就改了几遍。。。)

S = a * b * 0.5 * sin(C * pi / 180) ;
L = a + b + sqrt(a * a + b * b - a * b * 2.0 * cos (C * pi / 180));
h = 2.0 * S / a;

在表达式里,记得尽早用小数给运算转型,不然得到的值可能不准确。

还有那个sqrt,一开始我就把它漏了。

3.输出的时候
在这道题里,每个值是单独成行的(这个oj里一般是 a only space between each value,欻!这里竟是 \n !!! 小丑竟是我自己)

下面是完整的代码:

#include <stdio.h>
#include <math.h>
int main (){
	const double pi = 3.1415926;
	int a,b,C;
	scanf("%d %d %d",&a,&b,&C);
	double S,L,H;
	S = a * b * 0.5 * sin(C * pi / 180) ;
	L = a + b + sqrt(a*a + b*b - a * b * 2.0 * cos (C * pi / 180));
	H = 2.0 * S / a;
	printf("%lf\n%lf\n%lf\n",S,L,H);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值