my code:
- Code: Select all
#include<stdio.h>
#include<math.h>
int main(){
//freopen("a.in","r",stdin);
//freopen("b.in","w",stdout);
double x1,y1,x2,y2,y3,x3;
double h,k,r,g,f,c;
int flag=0;
while(1){
if(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3)!=6)
break;
double ma,mb;
char p='-',q='-',a='+',b='+',s='+';
if(x1==x2)
ma=1;
else
ma = (y1-y2)/(x1-x2);
if(x2==x3)
mb=1;
else
mb = (y2-y3)/(x2-x3);
h=((y1-y3)*ma*mb + mb*(x1+x2)-ma*(x2+x3))/(2*(mb-ma));
k=((x3-x1)-(y1+y2)*ma+(y2+y3)*mb)/(2*(mb-ma));
r=sqrt((x1-h)*(x1-h) + (y1-k)*(y1-k));
g=-2*h;
f=-2*k;
//c=h*h+k*k-r*r;
c = -(x2 * x2 + y2 * y2 + g * x2 + f * y2);
if(h<=0){
p='+';
h=-1*h;
}
if(k<=0){
q ='+';
k=-1*k;
}
printf("(x %c %.3lf)^2 + (y %c %.3lf)^2 = %.3lf^2\n",p,h,q,k,r);
if(g<0){
a='-';
g=-1*g;
}
if(f<0){
b ='-';
f=-1*f;
}
if(c<0){
s='-';
c=-1*c;
}
printf("x^2 + y^2 %c %.3lfx %c %.3lfy %c %.3lf = 0\n\n",a,g,b,f,s,c);
}
return 0;
}
