The Circumference of the Circle C语言 ZOJ1090

使用的是高中数学的一个公式,p=(a+b+c)/2,s=sqrt(p*(p-a)*(p-b)*(p-c)),由正弦定理a/sinA=b/sinB=c/sinC=2r,s=0.5*a*b*sinC,所以r=a*b*c/(4*s),然后就可以求周长了。

 1 #include <stdio.h>
 2 #include <math.h>
 3 #define pi 3.141592653589793 
 4 
 5 int main(void){
 6     double x1,y1,x2,y2,x3,y3,a,b,c,s,cir,r,p;
 7     while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
 8         a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
 9         b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
10         c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
11         p=(a+b+c)/2;
12         s=sqrt(p*(p-a)*(p-b)*(p-c));
13         r=a*b*c/(4*s);
14         cir=2*pi*r;
15         printf("%.2lf
",cir);
16     }
17     return 0;
18 }
View Code
原文地址:https://www.cnblogs.com/20174317zhuyuan/p/9389388.html