Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
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);
}