Back to list of problems
The Circumference of the Circle
438.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define PI 3.141592653589793 int main(int argc, char *argv[]) { char buf[1024]; double a1,a2,b1,b2,c1,c2; double circ; while(fgets(buf, 1024, stdin)) { double p1,p2,pm,pn,q1,q2,qm,qn; /* y = pm*x + pn */ double x,y; if (sscanf(buf, "%lf %lf %lf %lf %lf %lf", &a1, &a2, &b1, &b2, &c1, &c2)!=6) { exit(1); } if (a2==b2) { double t; t=a1; a1=c1; c1=t; t=a2; a2=c2; c2=t; } else if (a2==c2) { double t; t=a1; a1=b1; b1=t; t=a2; a2=b2; b2=t; } p1=(a1+b1)/2; p2=(a2+b2)/2; pm=(b1-a1)/(a2-b2); pn=p2-pm*p1; q1=(a1+c1)/2; q2=(a2+c2)/2; qm=(c1-a1)/(a2-c2); qn=q2-qm*q1; x = (qn-pn)/(pm-qm); y = pm*x + pn; circ = 2*PI*(sqrt((x-a1)*(x-a1)+(y-a2)*(y-a2))); printf("%.2f\n", circ); } exit(0); }