求角的度数

题意:给你三个点A(x,y),B(x,y),C(x,y),求∠ABC的度数,输出保留两位小数。

解法:余弦定理求出cos∠ABC的大小,根据PI=180°进行转换。

 1 #include <stdio.h>
 2 #include <math.h>
 3 using namespace std;
 4 float x[4],y[4];
 5 int main()
 6 {
 7     while(~scanf("%f%f%f%f%f%f",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2]))
 8     {
 9         float c=sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));
10         float a=sqrt((x[1]-x[2])*(x[1]-x[2])+(y[1]-y[2])*(y[1]-y[2]));
11         float b=sqrt((x[0]-x[2])*(x[0]-x[2])+(y[0]-y[2])*(y[0]-y[2]));
12         double ans= acos((a*a+c*c-b*b)/(2.0*a*c))*180/3.1415926;
13         printf("%.2f\n",ans);
14     }
15     return 0;
16 }

 

posted @ 2020-02-19 17:30  留幸愉  阅读(307)  评论(0编辑  收藏  举报